We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Centralizing watermark on pdf object

Hey,


I am trying to centralize the watermark i create using the PdfFileStamp object.
Since the length of the text differs i would be happy to know if there is a way to insure that
the watermark is placed “all over the page” rather than only on a partial part of it.

Thanks!
garkler

Hello Garkler,

Thanks for using our products.

In order to place a watermark all over the PDF document, you need to increase the size of text being placed or, in case you need to center align the watermark text being placed, then please specify the watermark origins as center of document. Please take a look over following code snippet in which I have specified the text font size as 50 (to be large enough to be displayed on document) and have specified the watermark origins from PdfFileInfo perspective.

[C#]

//Set the file names of the input and output PDF files
string inFile = "D:/pdftest/source.pdf";
string outFile = "d:/pdftest/source_updated.pdf";
// create PdfFileInfo object to get PDF file information
PdfFileInfo fileInfo = new PdfFileInfo(inFile);
// create Stamp object

Stamp aStamp = new Stamp();
// create a sample formatting text with Maroon as font color and text size as 50
FormattedText formatted = new FormattedText("Draft Document", System.Drawing.Color.Maroon, Aspose.Pdf.Kit.FontStyle.HelveticaBold, EncodingType.Winansi, true, 50);
aStamp.BindLogo(formatted);
aStamp.IsBackground = false;
// specify the page number over which watermark should be displayed
aStamp.Pages = new int[] { 1 };
// Watermark rotation angle
aStamp.Rotation = 45;
// specify the opacity value for watermark
aStamp.Opacity = 0.5F;|
//specifies the position of stamp
aStamp.SetOrigin(fileInfo.GetPageWidth(1) / 3, fileInfo.GetPageHeight(1) / 2);
PdfFileStamp stamper = new PdfFileStamp(inFile, outFile);
stamper.AddStamp(aStamp);
stamper.Close();

Please take a look over the attached source PDF file and the PDF document after watermark has been applied. In case it does not resolve your problem or you have any further query, please feel free to contact.