Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I customize the PDF from a PrimeFaces p:dataExporter, e.g. page size

I would like to change PDF page size to A4 landscape when exporting tables. But I cannot get it done whatever I do..

here is my code:

 <h:commandLink title="Export">
     <p:graphicImage value="/resources/theme-main/images/export/pdf.png" 
        style="border:0"/>
     <p:dataExporter target="myTable" type="pdf" fileName="name" 
        encoding="windows-1250" preProcessor="#{fileExportProcessor.preProcessPDF}"/>
 </h:commandLink>

where managed bean's method is very simple:

   public void preProcessPDF(Object document) {
      Document pdf = (Document) document;
      pdf.open();
      pdf.setPageSize(PageSize.A4.rotate());
    }

I also tried to set size to A0 or some my custom size, just to see it working, but nothing changed... PDF export exports only in A4 portrait mode.

Could you help me, how to make this work (A4 landscape mode)?

like image 615
igor Avatar asked Oct 04 '13 14:10

igor


1 Answers

Try this way :

public void preProcessPDF(Object document) {
      Document pdf = (Document) document;
      pdf.setPageSize(PageSize.A4.rotate());
      pdf.open();
    }

Worked for me !

like image 84
Erwann Avatar answered Oct 06 '22 20:10

Erwann