使用 Primefaces dataExporter 更改生成 pdf 的样式
我正在使用 Primefaces dataExporter 从数据表生成 pdf。生成的 pdf 所有列的宽度都相同。我正在寻找一种方法来更改后处理器/预处理器函数上的表格样式。我可以在生成 pdf 之前使用 setHtmlStyleClass 方法更改某些内容吗?我尝试使用它,但没有成功。我想我没有理解正确。
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
Document pdf = (Document) document;
pdf.setHtmlStyleClass("reportClass");
...
}
如果我可以使用该方法,我可以在哪里定义 reportClass ?它是浏览器页面的 css 类吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 PDFExporter.java导出方法,无法操作PDF中的数据表。
首先创建一个 com.itextpdf.text.Document 对象。
然后调用 preProcessor 方法传递 Document,这是在将表格添加到 PDF 文档之前。
然后创建
com.itextpdf.text.pdf.PdfPTable
。 exportPDFTable 方法不执行任何特殊格式设置。现在调用 postProcess 方法并再次传递 Document。在这里,我认为您将能够从 Document 对象访问和更改 PdfPTable,但查看 iText api 看起来似乎不能。
因此,如果您想要一个样式化的 PDF 表格,您必须实现自己的 PDF 导出。希望了解 PrimeFaces PDFExporter 的工作原理能够对您有所帮助。
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.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.PdfPTable
is 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.