I'm using Primefaces dataExporter to generate pdf from a dataTable. The pdf generated has all the columns with the same width. I'm looking for a way to change the style of the table on the postProcessor/preProcessor functions. Can I use the setHtmlStyleClass method to change something before generating pdf? I tried to use it, but with no success. I think I didnt understand it correctly.
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
Document pdf = (Document) document;
pdf.setHtmlStyleClass("reportClass");
...
}
If I can use that method, where can I define reportClass ? Is it a css class for the page on the browser?
If you look at whats going on in the PDFExporter.java export method, the data table in the PDF can not manipulated.
First a
com.itextpdf.text.Documentobject is created.Then the preProcessor method is called passing the Document, this is before the table is added to the PDF Document.
Then the
com.itextpdf.text.pdf.PdfPTableis created. The exportPDFTable method doesn't do any special formatting.Now the postProcess method is called and the Document is passed again. Here I would think you would be able to access and change the PdfPTable from the Document object but looking at the iText api it doesn't look like you can.
So if you want a styled PDF table your going to have to implement your own PDF export. Hopefully looking at how the PrimeFaces PDFExporter is done will help you with that.