How to add a Header/Footer on a PDF File with DroidText?

1.7k views Asked by At

I want to add a Header or a Footer on the first page of my PDF. I have tried to set it just after construct the Document. But, it was inneficient.

I also have thought of passing the first page and delete it at the end. But, I haven't managed it yet... :(

Has someone a solution ?

Thanks.

1

There are 1 answers

1
Pratik Butani On BEST ANSWER

Following code may useful to you:

Set Header:

//open the document
doc.open();

//set header
Phrase headerText = new Phrase("This is an example of a Header");
HeaderFooter pdfHeader = new HeaderFooter(headerText, false);
doc.setHeader(pdfHeader);

Set Footer:

//set footer
Phrase footerText = new Phrase("This is an example of a footer");
HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
doc.setFooter(pdfFooter);

//close doc
doc.close();