Hi,
We need some help on how to correctly apply a page centered watermark (both vertical and horizontal). We are able to make the watermark centered on horizontally but we cannot do it vertically.
Details:
1. Here is the code we are using:
var textStamp = new AsposePdf.TextStamp(watermark)
{
Background = false,
HorizontalAlignment = AsposePdf.HorizontalAlignment.Center,
VerticalAlignment = AsposePdf.VerticalAlignment.Center,
TextAlignment = AsposePdf.HorizontalAlignment.Left,
Rotate = AsposePdf.Rotation.None,
Opacity = .2f,
Width = page.Rect.Width - 80,
Height = page.Rect.Height - 200,
WordWrap = true,
Scale = true,
YIndent = 200,
};
textStamp.TextState.Font = FontRepository.FindFont(“Arial”);
textStamp.TextState.FontSize = 50.0F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.ForegroundColor = AsposePdf.Color.FromRgb(Color.Red);
textStamp.TextState.HorizontalAlignment = AsposePdf.HorizontalAlignment.Center;
pdfDocument.Pages[i].AddStamp(textStamp);
2. We are using version 17.3 of Aspose.Pdf library.
3. We attached the result. You can clearly see that the watermark is not vertically centered.
How can we achieve this?
Thank you.
Hi Panos,
using (Document pdfDocument = new Document(dataDir + “Page+centered+watermark.pdf”))<o:p></o:p>
{
foreach (Page page in pdfDocument.Pages)
{
TextStamp textStamp = new TextStamp("Test Watermark")
{
Background = false,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
TextAlignment = HorizontalAlignment.Left,
Rotate = Rotation.None,
Opacity = .2f,
//Width = page.Rect.Width - 80,
//Height = page.Rect.Height - 200,
WordWrap = true,
Scale = true
//YIndent = 200,
};
textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 50.0f;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Purple;
page.AddStamp(textStamp);
}
pdfDocument.Save(dataDir + "CenteredWatermark.pdf");
}
Hi,
Thank you for the quick response!
The code you send works perfect with a small watermark. With a watermark having 100 chars it will behave awkward. I can barely see the watermark now. Please check the attached PDF.
What I did:
1. Used the code you sent.
2.
Used the watermark ‘Controlled Document, 1. Controlled Document, 2.
Controlled Document, 3. Controlled Document, 4. Cont’ that has 100
chars.
We need to support big watermarks as well as they are managed by our users and are dynamically added in the PDF.
Are there any other ways to add watermarks?
Thank you!
Document doc = new Document();
Page p = doc.Pages.Add();
Artifact af = new Artifact(Artifact.ArtifactType.Background, Artifact.ArtifactSubtype.Watermark);
//af.SetImage(dataDir + "aspose.jpg");
//af.SetText(new Facades.FormattedText("Controlled Document, 1. Controlled Document, 2. Controlled Document, 3. Controlled Document, 4. Cont"));
af.ArtifactVerticalAlignment = VerticalAlignment.Center;
af.ArtifactHorizontalAlignment = HorizontalAlignment.Center;
af.SetTextAndState("Controlled Document, 1. Controlled Document, 2. Controlled Document, 3. Controlled Document, 4. Cont", new TextState() { FontSize = 50.0f, Font = FontRepository.FindFont("Arial"), ForegroundColor = Color.Purple });
af.Opacity = .2f;
p.Artifacts.Add(af);
doc.Save(dataDir + "Artifacts.pdf");