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

Free Support Forum - aspose.com

Adding footer details to Existing PDF

hi Support,

I need some help in getting footer section with details below

Date: on left bottom
Note: on center bottom
Page Number: on right bottom,

On existing static PDF document of 20 pages (combination on both Patriot and Landscape layouts).
I saw adding a text section using PdfFileStamp for adding page numbers. where i would like to add all the three details above in a specified alignment.

Please let me know.

Thanks,

Hi Rajesh,


Thanks for contacting support.

In order to accomplish this requirement, please consider using following code snippet.

[Java]

// Create Document instance<o:p></o:p>

com.aspose.pdf.Document doc = new com.aspose.pdf.Document("c:/pdftest/Portrait.pdf");

// instantiate FormattedText object with sample string

com.aspose.pdf.TextStamp text = new com.aspose.pdf.TextStamp ("Date :- 07Dec15");

text.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Left);

text.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Bottom);

// instantiate FormattedText object with sample string

com.aspose.pdf.TextStamp Note = new com.aspose.pdf.TextStamp ("Note Text");

Note.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);

Note.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Bottom);

//create page number stamp

com.aspose.pdf.PageNumberStamp pageNumberStamp = new com.aspose.pdf.PageNumberStamp();

//whether the stamp is background

pageNumberStamp.setBackground(false);

pageNumberStamp.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Right);

pageNumberStamp.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Bottom);

// iterate through all pages of PDF file

for (int Page_counter =1; Page_counter<=doc.getPages().size();Page_counter++)

{

//add stamp to all pages of PDF file

doc.getPages().get_Item(Page_counter).addStamp(text);

//add stamp to all pages of PDF file

doc.getPages().get_Item(Page_counter).addStamp(Note);

//add stamp to all pages of PDF file

doc.getPages().get_Item(Page_counter).addStamp(pageNumberStamp);

}

//save output document

doc.save(“c:/pdftest/PageNumberStamp_output.pdf”);

Thank you Nayyar,

The snippet provided works great, but there is not proper padding, horizontal alignment and page number gets truncated from double digits.

Attaching the output document.

Please advise how can i make this better.

And how to avoid the footer details in blank pages.

Please let me know.

Thanks,

Rajesh

Hi Rajesh,


Thanks for sharing the details.

In order to set padding and properly display page number information, please set page margin information. Please try using following code line.

[Java]
pageNumberStamp.setRightMargin(20);