如何从PrimeFaces p:dataExporter自定义PDF,例如页面大小 [英] How do I customize the PDF from a PrimeFaces p:dataExporter, e.g. page size

查看:200
本文介绍了如何从PrimeFaces p:dataExporter自定义PDF,例如页面大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在导出表格时将PDF页面大小更改为A4 横向.但是我做不了任何事情.

这是我的代码:

  <h:commandLink title="Export">
     <p:graphicImage value="/resources/theme-main/images/export/pdf.png" 
        style="border:0"/>
     <p:dataExporter target="myTable" type="pdf" fileName="name" 
        encoding="windows-1250" preProcessor="#{fileExportProcessor.preProcessPDF}"/>
 </h:commandLink>
 

托管bean的方法非常简单:

    public void preProcessPDF(Object document) {
      Document pdf = (Document) document;
      pdf.open();
      pdf.setPageSize(PageSize.A4.rotate());
    }
 

我还尝试将大小设置为A0或一些我的自定义大小,只是为了查看它是否起作用,但没有任何变化.

您能帮助我,如何进行这项工作(A4横向模式)吗?

解决方案

尝试这种方式:

public void preProcessPDF(Object document) {
      Document pdf = (Document) document;
      pdf.setPageSize(PageSize.A4.rotate());
      pdf.open();
    }

为我工作!

I would like to change PDF page size to A4 landscape when exporting tables. But I cannot get it done whatever I do..

here is my code:

 <h:commandLink title="Export">
     <p:graphicImage value="/resources/theme-main/images/export/pdf.png" 
        style="border:0"/>
     <p:dataExporter target="myTable" type="pdf" fileName="name" 
        encoding="windows-1250" preProcessor="#{fileExportProcessor.preProcessPDF}"/>
 </h:commandLink>

where managed bean's method is very simple:

   public void preProcessPDF(Object document) {
      Document pdf = (Document) document;
      pdf.open();
      pdf.setPageSize(PageSize.A4.rotate());
    }

I also tried to set size to A0 or some my custom size, just to see it working, but nothing changed... PDF export exports only in A4 portrait mode.

Could you help me, how to make this work (A4 landscape mode)?

解决方案

Try this way :

public void preProcessPDF(Object document) {
      Document pdf = (Document) document;
      pdf.setPageSize(PageSize.A4.rotate());
      pdf.open();
    }

Worked for me !

这篇关于如何从PrimeFaces p:dataExporter自定义PDF,例如页面大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆