2017-10-27 6 views
0

JSFのiTextを使用してデータテーブルをPDFにエクスポートしたいと思います。 そのために、Prime Faces 'の実装を使用しています。iTextのレイアウト変更はPrimeFacesのプリプロセッサの最初のページには影響しません

すべて動作しますが、PDFのレイアウトを変更したいと思います。まず、風景のページの向き。 PrimeFacesで提案されているプリプロセッサメソッドを使用しています。

私の問題はで、PDFの最初のページは変更の影響を受けず、次のものだけが影響を受けます。

私はこれがPrime Faces関連の問題だとよく分かりますか?この問題に関するGoogleの解決策は見つかりませんでした。 私は何か間違った設定をしているかもしれないと思っていますが、どこに見えませんでした。

親切にお手伝いいただきありがとうございます。

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()); 
} 

出力:

The result of the above code

更新:

PDFOptionsは、最初のページに取り組んでいるが、前処理はまだいません。

<p:dataExporter type="pdf" target="tbl" 
           fileName="#{resourceHandler.getString('attendance.filename')}" 
           preProcessor="#{presenceController.preProcessPDF}" 
           options="#{presenceController.pdfOpt}" /> 

答えて

0

private PDFOptions pdfOpt; 

@PostConstruct 
public void setupPdf() { 
    pdfOpt = new PDFOptions(); 
    pdfOpt.setCellFontSize("1"); 
} 

私は、前処理のコードを変更することで問題を解決:、我々はページサイズを変更する必要があり

はその後文書を開きます。

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { 
      Document pdf = (Document) document; 
      pdf.setPageSize(PageSize.A4.rotate()); 
      pdf.open(); 
} 
関連する問題