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.
-
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.
-
Regarding the second requirement, please try using the IsWatermarkOnTop property of the
Pdf
class and set its value tofalse
. -
I’m not sure what sort of Image placeholder you are using. I would suggest you use a
FloatingBox
to place an image file as well. I’ve tried to replicate the scenario using the following code snippet and have generated a sample PDF document. In this case, theBoxVerticalAlignmentType
is set toTop
. Please take a look. The file is also in the attachment.
Pdf pdf1 = new Pdf();
Section section = pdf1.Sections.Add();
Text text = new Text("DO NOT COPY");
text.TextInfo.FontSize = 40.0f;
text.RotatingAngle = 45.0f;
text.TextInfo.Color = new 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
Image image1 = new Image();
image1.ImageInfo.File = @"d:/pdftest/Penguin.PNG";
image1.ImageInfo.ImageFileType = ImageFileType.Png;
FloatingBox watermark1 = new 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;
section.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 visit the following link for information on Customizing Watermark.
Hello Vaibhav,
Thanks for your patience.
I’m pleased to inform you that the issue reported earlier PDFNET-10518 on this forum thread is resolved in the hotfix shared over this link. Please try using it and feel free to contact me in case you face any problems or have any further queries.
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,
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