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

Free Support Forum - aspose.com

Adding watermarks on different sized pages in same PDF file

I have PDF Documents that have pages that come in many different sizes but in one PDF document. What is happening is that when I try placing watermarks on these documents I sometimes get a result where the watermark is much to large or to small for some of the pages. Right now it all depends on the first page. Example: I have a PDF where the first page is four times the size of the rest of the pages in the PDF. The first page comes out great but the rest of the pages only part of the watermark fits because it’s been scaled to the first page only.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Is there a way that I can scale the watermark for each individual page in the same PDF file?

Here is the example of the code I use now.

Dim TextSize As Integer

Dim license As Aspose.Pdf.Kit.License = New Aspose.Pdf.Kit.License
license.SetLicense("********")

Dim inFile As String = PDFFileLocation
Dim outFile As String = NewName

Dim fileInfo As PdfFileInfo = New PdfFileInfo(inFile)


TextSize = ((((fileInfo.GetPageWidth(1) + fileInfo.GetPageHeight(1)) / 2) / 700) * 40)


Dim fftext As FormattedText

fftext = New FormattedText("Uncontrolled In Hard Copy", New FontColor(0, 200, 0), FontStyle.Helvetica, EncodingType.Winansi, False, TextSize)

Dim aStamp As Stamp = New Stamp
aStamp.BindLogo(fftext)

aStamp.Rotation = 45
aStamp.Opacity = 0.2

aStamp.SetOrigin((fileInfo.GetPageWidth(1) / 4), (fileInfo.GetPageHeight(1) / 4))

Dim stamper As PdfFileStamp = New PdfFileStamp(inFile, outFile)

stamper.AddStamp(aStamp)

stamper.Close()

Thank you

Hi,

Can you please share the pdf document as well? I'm sure that'll help us resolve the issue.

We appreciate your patience and cooperation.

Regards,

Sure, I had to create a crude example of a PDF with three pages all different sizes.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

When viewing the document, you cannot see the size difference until you go to each pages properties.

First page should be 11 x 17

Second page should be 8 x 11

Third page is something like 3 x 4

Is there a way that I could rescale the watermark either by the entire watermark being resized or resizing the Text size of the watermark from page to page.

Usually this problem comes from when my company had to scan in very large paper documents and also have a normal sized page scanned in as one PDF.

Thank you

Hi,

Thanks for sharing the resources. We are looking into the details of this problem and will reply to you soon.

Hi Andrew,

I have modified the code snippet a little bit. I have also attached the output pdf file as well. I'm sure this will resolve the issue.


Dim viewer As New PdfViewer

viewer.OpenPdfFile("...input file path...")
Dim pagecount As Integer
pagecount = viewer.PageCount

Dim inFile As String = "...input file path..."
Dim outFile As String = "...output file path..."
Dim i As Integer
Dim stamper As PdfFileStamp = New PdfFileStamp(inFile, outFile)
Dim fileInfo As PdfFileInfo = New PdfFileInfo(inFile)

For i = 1 To pagecount

Dim TextSize As Integer

'Dim license As Aspose.Pdf.Kit.License = New Aspose.Pdf.Kit.License
'
license.SetLicense("*****")

TextSize = ((((fileInfo.GetPageWidth(i) + fileInfo.GetPageHeight(i)) / 2) / 700) * 40)

Dim fftext As FormattedText

fftext = New FormattedText("Uncontrolled In Hard Copy", New FontColor(0, 200, 0), FontStyle.Helvetica, EncodingType.Winansi, False, TextSize)

Dim aStamp As Stamp = New Stamp
aStamp.BindLogo(fftext)

aStamp.Rotation = 45

aStamp.Opacity = 0.2

aStamp.SetOrigin((fileInfo.GetPageWidth(i) / 4), (fileInfo.GetPageHeight(i) / 4))

Dim arr(1) As Integer
arr(0) = i
aStamp.Pages = arr

stamper.AddStamp(aStamp)

Next

stamper.Close()

I hope this helps. If you have any further questions, please do let us know.

Regards,

This looks like this works with the documents that I have at work. I noticed there might be a little bit of a slow down from start to finish but its reasonable.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for the Help.