Hi,
I’m tiring to get watermark text from pdf. The document is watermarked with the following code:
var document = new Aspose.Pdf.Document(filename);
var wmFontSize = ws.FontSize;
var wmText = ws.Text;
var lines = wmText.Split(new string[] { "\r\n", "\r", "\\r", "\n", "\\n" }, StringSplitOptions.RemoveEmptyEntries);
var text = new FormattedText();
foreach (var l in lines)
{
text.AddNewLineText(l);
}
var stamp = new TextStamp(text)
{
Opacity = ws.Transparency < 0.01 ? 1 : 1 - ws.Transparency,
TopMargin = 10,
LeftMargin = 10,
RightMargin = 10,
BottomMargin = 10
};
var textAlignment = GetHorizontalAlignment(ws.TextAlignment);
stamp.TextAlignment = textAlignment;
if (textAlignment == HorizontalAlignment.Justify)
{
stamp.HorizontalAlignment = HorizontalAlignment.Center;
stamp.VerticalAlignment = VerticalAlignment.Center;
}
else
{
stamp.HorizontalAlignment = textAlignment;
stamp.VerticalAlignment = GetVerticalAlignment(ws);
}
if (ws.RotationAngle == RotationAngleConsts.HEADER)
stamp.VerticalAlignment = VerticalAlignment.Top;
else if (ws.RotationAngle == RotationAngleConsts.FOOTER)
stamp.VerticalAlignment = VerticalAlignment.Bottom;
else if (ws.RotationAngle == RotationAngleConsts.VERTICAL)
stamp.RotateAngle = 90;
else if (ws.RotationAngle == RotationAngleConsts.DIAGONAL)
stamp.RotateAngle = 45;
stamp.TextState.Font = FontRepository.FindFont(ws.FontType);
stamp.TextState.FontSize = wmFontSize;
stamp.TextState.FontStyle = ws.WMFontStyles;
stamp.TextState.Underline = ws.Underline;
stamp.TextState.StrikeOut = ws.Strikeout;
stamp.TextState.ForegroundColor = ws.GetColor();
foreach (var page in document.Pages)
{
page.AddStamp(stamp);
}
var ownerPassword = Guid.NewGuid().ToString();
var userPassword = ws.PasswordForOpening ?? "";
var documentPrivilege = ws.DocumentPrivilege;
var allPrivilegesAllowed = ws.AllPrivilegesAllowed(documentPrivilege);
if (!allPrivilegesAllowed || !string.IsNullOrWhiteSpace(userPassword))
{
documentPrivilege.AllowAssembly = false;
document.Encrypt(userPassword, ownerPassword, documentPrivilege, CryptoAlgorithm.RC4x128, false);
}
document.Metadata.RegisterNamespaceUri("xmp", "http://ns.adobe.com/xap/1.0/");
document.Metadata["xmp:IsWatermarkedByDynamo"] = "true";
document.Save(resultFile);
Then I’m trying to get the artifact info with the following code:
var pdfDocument = new Aspose.Pdf.Document(file, password);
var aftifact = pdfDocument.Pages[1].PageInfo;
foreach (var artifact in pdfDocument.Pages[1].Artifacts)
{
var textState = artifact.TextState;
Assert.AreEqual(ws.FontType, textState.Font.FontName);
Assert.AreEqual(ws.FontSize, textState.FontSize);
Assert.AreEqual(ws.WMFontStyles, textState.FontStyle);
Assert.AreEqual(ws.GetColor().ToString(), textState.ForegroundColor.ToString());
Assert.AreEqual(ws.Transparency < 0.01 ? 1 : 1 - ws.Transparency, artifact.Opacity);
**Assert.AreEqual(ws.Text, artifact.Text);**
}
Everything looks fine except artifact.Text. It is empty.