Page 1 of 1

Header for the first page of pfd export

Posted: 19 Jan 2011, 09:48
by mikke
Hi!

I tried to add custom header and footer for my exported pdf. I added preProcessPdf and tried to add header for the document:

Code: Select all

	public void preProcessPDF(Object document) throws DocumentException {
                Document pdf = (Document)document;
		
		HeaderFooter header = new HeaderFooter(Phrase.getInstance(getHeader()), true);
		
		pdf.setHeader(header);
		HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), new Phrase("."));
		pdf.setFooter(footer);
       }
This will add header and footer for the next pages but not to the first page. I assume that the problem is document is opened before preProsess is invoked in prime's PDFExporter.

From the doc of com.lowagie.text.Document.open:
Opens the document.
Once the document is opened, you can't write any Header- or Meta-information anymore. You have to open the document before you can begin to add content to the body of the document.
Could there be added "onBeforeOpen" event for dataexporter? Or does some have a trick how to get header for the first page?

Re: Header for the first page of pfd export

Posted: 10 Oct 2013, 03:52
by aosama
any luck with your issue, i am facing this situation where there is no header or footer added to the first page

public void preProcessPDF(Object document)
{
try
{
System.out.println("working on pdf");
Document pdf = (Document) document;
pdf.open();
pdf.setPageSize(PageSize.A4);

Phrase phraseBefore = new Paragraph("this is the phrase before");
Phrase phraseAfter = new Paragraph("this is the phrase after");

HeaderFooter header = new HeaderFooter(phraseBefore, true);

pdf.setHeader(header);
} catch (Exception e)
{
System.out.println(e.toString());
}

}

Re: Header for the first page of pfd export

Posted: 10 Oct 2013, 13:16
by sudheer
Don't raise old threads and make a new topic.

Yes,it is adding the header and footer in 2nd page onwards only.But Itext 5 provided with examples http://examples.itextpdf.com/results/pa ... tries1.pdf.I feel it will be avaialble in itext 2.1.7 with HeaderFooter classes.

Better you simply create small java app(without JSF,PF etc) using itext 2.1.7.If it works for all the pages then you can implement with export feature.