如何从PrimeFaces p:dataExporter自定义PDF,例如页面大小

编程入门 行业动态 更新时间:2024-10-27 14:26:19
本文介绍了如何从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,例如页面大小

本文发布于:2023-07-26 09:27:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1215497.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   大小   页面   PrimeFaces   dataExporter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!