Header for the first page of pfd export

UI Components for JSF
Post Reply
mikke
Posts: 7
Joined: 15 Dec 2010, 10:32

19 Jan 2011, 09:48

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?
Apache tomcat 7.0.6, Myfaces 2.0.2, Primefaces 2.2.RC

aosama
Posts: 18
Joined: 07 Jun 2013, 22:10

10 Oct 2013, 03:52

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());
}

}

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4344
Joined: 16 Oct 2011, 19:19
Location: Singapore

10 Oct 2013, 13:16

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.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 19 guests