Text based watermark not displayed properly on PDF

Hi,

I want to add a Text watermark on my PDF document. I have used the following code to get the watermark added to the PDF instance:
//text watermark
Text text = new Text(“DO NOT COPY”);
text.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
text.TextInfo.FontSize = 40.0f;
text.RotatingAngle = 45.0f;
FloatingBox watermark = new FloatingBox(500, 200) { BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin, BoxHorizontalAlignment = BoxHorizontalAlignmentType.Center, BoxVerticalPositioning = BoxVerticalPositioningType.Margin, BoxVerticalAlignment = BoxVerticalAlignmentType.Center, ZIndex = -1};
watermark.Paragraphs.Add(text);
pdf.Watermarks.Add(watermark);

I am facing the following issues in the above code:
1. The watermark is not positioned in the center of the document but goes all the way towards the left side angled at 45 degrees. When I remove/comment the line text.RotatingAngle = 45.0f; the text starts coming in the center of the document properly. Please assist in getting the text at the center with RotatingAngle
@ 45 degrees.

2. I need the text watermark to be placed behind the PDF content. For that I have set the ZIndex to -1 but it still renders as plain text over the PDF content.

3. I am placing some image in the PDF at an image place holder at run time. When the image is placed over the PDF the watermark goes below the image and is cut off on the page. I tried to set the opacity of the image to around 0.5 but that’s not working for me as at higher opacity it just whitens the image and makes it invisible. Any solution/work around for this…

Thanks,
Vaibhav Modak

Hello Vaibhav,

Thanks for considering Aspose.

1) I've tested the scenario and I'm able to reproduce the same problem. I have logged it in our issue tracking system as PDFNET-10518. We will investigate this issue in detail and will keep you updated on the status of a correction. We apologize for your inconvenience.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

2) Regarding second requirement, please try using the IsWatermarkOnTop property of Pdf class and set its value to false.

3) I'm not sure what sort of Image place holder you are using. I would suggest you to use FloatingBox to place an image file as well. I've tried to replicate the scenario using following code snippet and have generated a sample PDF document. In this case, the BoxVerticalAlignmentType is set to Top. Please take a look. The file is also in attachment.

[C#]

Pdf pdf1 = new Pdf();
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

Text text = new Text("DO NOT COPY");
text.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
text.TextInfo.FontSize = 40.0f;
text.RotatingAngle = 45.0f;
text.TextInfo.Color = new Aspose.Pdf.Color("gray");

FloatingBox watermark = new FloatingBox(500, 200);
watermark.BoxVerticalPositioning = BoxVerticalPositioningType.Margin;
watermark.BoxVerticalAlignment = BoxVerticalAlignmentType.Top;
watermark.ZIndex = -1;
watermark.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin;
watermark.Paragraphs.Add(text);
pdf1.Watermarks.Add(watermark);

//setting image watermark
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
image1.ImageInfo.File = @"d:/pdftest/Penguin.PNG";
image1.ImageInfo.ImageFileType = ImageFileType.Png;

Aspose.Pdf.FloatingBox watermark1 = new Aspose.Pdf.FloatingBox(108, 80);
watermark1.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;
watermark1.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Center;
watermark1.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
watermark1.BoxVerticalAlignment = BoxVerticalAlignmentType.Top;
watermark1.Padding.Top = 60;
watermark1.Paragraphs.Add(image1);
pdf1.Watermarks.Add(watermark1);
pdf1.IsWatermarkOnTop = false;

pdf1.Sections[0].Paragraphs.Add(new Text(" Aspose.Pdf is a .NET Component built to ease the job of developers to create PDF documents ranging from simple to complex on the fly programmatically. Aspose.Pdf allows developers to insert Tables, Graphs, Images, Hyperlinks and Custom Fonts etc. in the PDF documents. Moreover, it is also possible to compress PDF documents. Aspose.Pdf provides excellent security features to develop secure PDF documents. And the most distinct feature of Aspose.Pdf is that it supports the creation of PDF documents through both an API and from XML templates "));

pdf1.Save(@"d:/pdftest/Watermark_Issue.pdf");

I would suggest you to visit the following link for information on Customizing Watermark.

Hello Vaibhav,

Thanks for your patience.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I'm pleased to inform you that, the issue reported earlier PDFNET-10518 in this forum thread is resolved in the hotfix shared over this link.

Please try using it and in case you still face any problem or you've any further query, please feel free to contact.

The issues you have found earlier (filed as 10518) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi Nayyar,


I am adding water into the pdf exactly the same way you have mention but the watermark is still coming in front of the contents of the pdf , please your prompt help will be appreciate , code which i am using is below.


Dim textWT as New Text(“DO NOT COPY”)
textWT.TextInfo.Alignment = Aspose.Pdf.AlignmentType.Center
textWT.TextInfo.FontSize = 40.0f
textWT.RotatingAngle = 45.0f
Dim watermark as new FloatingBox(500, 200)
watermark.BoxVerticalPositioning = BoxVerticalPositioningType.Margin
watermark.BoxVerticalAlignment = BoxVerticalAlignmentType.Center
watermark.ZIndex = -1
watermark.BoxHorizontalPositioning = BoxHorizontalPositioningType.Margin
watermark.Paragraphs.Add(textWT)
pdf.Watermarks.Add(watermark)
pdf.IsWatermarkOnTop = false

thanks

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan