开发者

changing style on generating pdf with Primefaces dataExporter

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");
    开发者_StackOverflow...
}

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.Document object is created.

Document document = new Document(PageSize.A4.rotate());

Then the preProcessor method is called passing the Document, this is before the table is added to the PDF Document.

if(preProcessor != null) {
    preProcessor.invoke(facesContext.getELContext(), new Object[]{document});
}

Then the com.itextpdf.text.pdf.PdfPTable is created. The exportPDFTable method doesn't do any special formatting.

PdfPTable pdfTable = exportPDFTable(table, excludeColumns);
document.add(pdfTable);

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.

if(postProcessor != null) {
    postProcessor.invoke(facesContext.getELContext(), new Object[]{document});
}

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜