【发布时间】:2022-01-31 18:16:45
【问题描述】:
我想使用 JSF 中的 iText 将数据表导出为 PDF。 为此,我使用了 Prime Faces 的实现。
一切正常,但我想更改 PDF 的布局。首先,页面方向为横向。为此,我使用了 PrimeFaces 建议的预处理器方法。
我的问题是 PDF 的第一页不受更改的影响,仅影响下一页。
我是否理解得很好,这是与 Prime Faces 相关的问题?我在谷歌上没有找到任何关于这个问题的解决方案。 我想也许我配置错了,但我没看到哪里。
感谢您的热心帮助。
xhtml:
<p:dataExporter type="pdf" target="tbl" fileName="#{resourceHandler.getString('attendance.filename')}" preProcessor="#{presenceController.preProcessPDF}" />
上面代码的(简化的)“上下文”:
<!DOCTYPE html>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui" encoding="UTF-8">
<html>
<h:head></h:head>
<h:body>
<ui:composition template="layout.xhtml">
<ui:define name="contentWrap">
<h:form id="display">
<p:commandButton
value="#{resourceHandler.getString('attendance.get')}"
action="#{presenceController.populate()}" update="display tbl" />
<p:dataTable id="tbl" var="pdto"
value="#{presenceController.presenceList}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
paginator="true" rows="10" style="margin-bottom:20px">
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage value="assets/img/pdf.png" width="24" />
<p:dataExporter type="pdf" target="tbl"
fileName="#{resourceHandler.getString('attendance.filename')}" preProcessor="#{presenceController.preProcessPDF}" />
</h:commandLink>
</f:facet>
<p:column id="lastName"
headerText="#{resourceHandler.getString('attendance.lastname')}">
<h:outputText value="#{pdto.lastName}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
</f:view>
方法:
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
Document pdf = (Document) document;
pdf.open();
pdf.setPageSize(PageSize.A4.rotate());
}
更新:
PDFOptions 正在处理第一页,但预处理仍然没有。
private PDFOptions pdfOpt;
@PostConstruct
public void setupPdf() {
pdfOpt = new PDFOptions();
pdfOpt.setCellFontSize("1");
}
与
<p:dataExporter type="pdf" target="tbl"
fileName="#{resourceHandler.getString('attendance.filename')}"
preProcessor="#{presenceController.preProcessPDF}"
options="#{presenceController.pdfOpt}" />
【问题讨论】:
标签: jsf primefaces itext