Free Support Forum - aspose.com

Page numbers and margin

On this form the margin is set to .5 inches on the top. So adding page numbers does not work because it applies them over the document text. A great feature would be a special character in the logostamp so that we could place into the string to insert that pages page number, or some way to change the margin on the fly, or someway to force the pagenumber string to ignore the margins.

Currently I am at a loss as the stamp will occur with the document locked. Therefore using the fileinfo to obtain the page count will not work and the pageview takes too much time to simply obtain the page count. Any ideas would be fantastic.

Sincerely,

Hi,

Thank you for considering Aspose.

Please try the following code snippet .

Stamp stamp = new Stamp();
FormattedText text = new FormattedText("Page XXX",
System.Drawing.Color.Blue, Aspose.Pdf.Kit.FontStyle.TimesRoman,
EncodingType.Winansi, false, 8);
stamp.BindLogo(text);
stamp.SetOrigin(290F, 10F); // as bottom of the page

Stamp stamp1 = new Stamp();
stamp1.BindLogo(text);
stamp1.SetOrigin(290F, 768F); // or, stampping on the top

PdfFileStamp filestamp = new PdfFileStamp("e://cm010.pdf","e://stampMargin.pdf");
filestamp.AddStamp(stamp1);
filestamp.AddStamp(stamp);
filestamp.Close();

Thank you for the reply. However I am not having trouble stamping the document, but rather getting the page numbers because the document is locked and the inability to use addpagenumber because the margins are off.

Here is the working (extremely slow) code in vb.net

'Use the same outputstream that we used above
Dim fileStamp As PdfFileStamp = New PdfFileStamp(workingFileStream, workingFileStream)

Dim pageview As New PdfViewer
pageview.OpenPdfFile(workingFileStream)
Dim count As Integer = pageview.PageCount
pageview.ClosePdfFile()


For i As Integer = 1 To count
Dim faxHeader As New Stamp
faxHeader.Pages = New Integer() {i}
faxHeader.SetOrigin(10, 780)
faxHeader.BindLogo(New FormattedText(String.Format(config.FaxHeaderStamp, Format(Now, config.FaxHeaderDateFormat), i)))
fileStamp.AddStamp(faxHeader)
Next

'this would have worked but the margin is too large on the top
'fileStamp.AddPageNumber(New FormattedText(String.Format(config.FaxHeaderStamp, Format(Now, config.FaxHeaderDateFormat))))

'Close the stamper
fileStamp.Close()

'Close the output stream
workingFileStream.Close()

If would be great if the PdfFileStamp had a property for PageCount. That would allow me to solve this problem without having to use the PDFViewer to reopen the document.

Sincerely

Hi,

Thanks for your suggestion, and we will consider adding such property to PdfFileStamp in future version.

You should use PdfPageEditor.GetPages() or PdfFileInfo.NumberofPages, instead of PdfViewer.PageCount, for better performance. Because that the PdfViewer will load real pages to memory.

Thanks,