我正在使用Primefaces dataExporter从dataTable生成pdf.生成的pdf具有相同宽度的所有列.我正在寻找一种方法来改变postProcessor/preProcessor函数上表的样式.在生成pdf之前,我可以使用setHtmlStyleClass方法更改内容吗?我试图使用它,但没有成功.我想我没有理解它.
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
Document pdf = (Document) document;
pdf.setHtmlStyleClass("reportClass");
...
}
Run Code Online (Sandbox Code Playgroud)
如果我可以使用该方法,我可以在哪里定义reportClass?它是浏览器页面的css类吗?
如果您查看PDFExporter.java导出方法中的最新情况,则无法操作PDF中的数据表.
首先com.itextpdf.text.Document创建一个对象.
Document document = new Document(PageSize.A4.rotate());
Run Code Online (Sandbox Code Playgroud)
然后调用preProcessor方法传递Document,这是在将表添加到PDF Document之前.
if(preProcessor != null) {
preProcessor.invoke(facesContext.getELContext(), new Object[]{document});
}
Run Code Online (Sandbox Code Playgroud)
然后com.itextpdf.text.pdf.PdfPTable创建.exportPDFTable方法不执行任何特殊格式设置.
PdfPTable pdfTable = exportPDFTable(table, excludeColumns);
document.add(pdfTable);
Run Code Online (Sandbox Code Playgroud)
现在调用postProcess方法并再次传递Document.在这里,我认为你可以从Document对象访问和更改PdfPTable,但是看看iText api它看起来不像你能做到的那样.
if(postProcessor != null) {
postProcessor.invoke(facesContext.getELContext(), new Object[]{document});
}
Run Code Online (Sandbox Code Playgroud)
因此,如果您需要样式化的PDF表格,则必须实现自己的PDF导出.希望看看PrimeFaces PDFExporter如何完成将帮助您.
| 归档时间: |
|
| 查看次数: |
9488 次 |
| 最近记录: |