<p:dataExporter type="pdf" target="callRpt"preProcessor="#{pc_CallReportBean.preProcessPDF}"
fileName="#{reportLbl['callReport.callsReportFileName']}" />
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException
{
Document pdf = (Document) document;
pdf.open();
pdf.setPageSize(PageSize.A4);
ServletContext servletContext = (ServletContext)FacesContext.
getCurrentInstance().getExternalContext().getContext();
String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "prime_logo.png";
pdf.add(Image.getInstance(logo));
}
在上面的代码中,我们使用primefaces的标签以pdf格式导出表格 我在首页设置了徽标。
如何使用p:dataExporter?
设置页码,页眉和页脚如果生成的页数超过1页,还想在每个页面设置表格标题吗?
答案 0 :(得分:2)
由于我假设您使用iText作为PDF生成器,因此您应该实现PdfPageEventHelper
来创建页眉和页脚。使用此功能,您将能够在每个页脚中增加页码。
这是一个完整的example,展示了如何实现它。