Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to Add Text in Header/Footer Area of PDF File in Android Applications

sheraz786sheraz786 Posts: 17Member

This technical tip shows how developers can add text in header or footer of a PDF file inside their Android applications. The TextStamp class is used to add text in PDF document. We can also use the same class to add text in Header/Footer area of PDF file. The TextStamp class provides necessary methods to specify font size, font style, and font color etc for stamp object. In order to add text in the Header area, first you need to create a Document object and a TextStamp object using required methods. After that, you can call addStamp(..) method of Page class to add text in the PDF file. Please note that when placing text in Header section, you need to call setTopMargin(..) in such a way that it adjusts the text in the header area of your PDF. Similarly when placing text in Footer section, you need to call setBottomMargin(..) in such a way that it adjusts to the text in Footer area.

• When adding stamp object in Header section, you also need to set VerticalAlignment to Top. • When adding stamp object in Footer section, you also need to set VerticalAlignment to Bottom.

The following code snippet shows you how to add text in the header of a PDF file.

//open document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("/mnt/sdcard/input.pdf");
//create text stamp
com.aspose.pdf.TextStamp textStamp = new com.aspose.pdf.TextStamp("Sample Stamp");
//set properties of the stamp

//set text properties
textStamp.getTextState().setFont(new com.aspose.pdf.FontRepository().findFont("Arial"));

// iterate through all pages of PDF file
for (int Page_counter =1; Page_counter<=pdfDocument.getPages().size();Page_counter++)
    //add stamp to all pages of PDF file
//save output document"/mnt/sdcard/TextStamp_output.pdf");
Sign In or Register to comment.