在Primefaces中更改默认格式dataExporter [英] change default format dataExporter in Primefaces

查看:441
本文介绍了在Primefaces中更改默认格式dataExporter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用来生成pdf dataexporter,使用方法预处理器来插入一些内容。通过给出类型字母大小页面可以很好地同化文本格式。然后进行分页以将图表放在新页面上,正确的问题是生成具有其他大小的第二页,并且还找到一种方法来更改导出表的文本的字体大小。

I want to use to generate a pdf dataexporter, use the method preprocessor to insert some content. By giving the type letter size page assimilates well as formats of texts. Then make a page break to put the chart on a new page, right there is the problem that generates the second page with other size and also find a way to change the font size of the text of the exported table.

<h:commandLink>  
      <p:graphicImage value="/images/pdf.png"/> 
             <p:dataExporter type="pdf" target="dataTableAddDetalles" fileName="pdf" preProcessor="#{serviciosMB.preProcessPDF}"/>  
</h:commandLink>

支持豆

 public void preProcessPDF(Object document) throws Exception {
    try {
        Document pdf = (Document) document;
        pdf.open();
        pdf.setPageSize(PageSize.LETTER);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "header.gif";

       // pdf.add(Image.getInstance(logo));
        pdf.add(new Paragraph("EMNI", FontFactory.getFont(FontFactory.HELVETICA, 22, Font.BOLD, new Color(0, 0, 0))));
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");

        pdf.add(new Phrase("Fecha: " + formato.format(new Date())));
        pdf.newPage();
    } catch (Exception e) {
        //JsfUtil.addErrorMessage(e, e.getMessage());
    }
}


推荐答案

primefaces文档(截至4.0)没有提到编写自定义数据导出器的任何能力,只有pre& amp;后处理器,在PDF的情况下阻止您对数据进行大量修改等。

The primefaces documentation (as of 4.0) does not mention any ability to write a custom data exporter, only pre & post processors, which in the case of PDF prevents you from doing extensive modifications to data, etc.

但您可以做的是在项目中创建一个名为

But what you can do is create a package in your project called

org.primefaces.component.export

并从primefaces源复制 ExporterFactory.java
然后您可以用自己的实现替换原来的 PDFExporter 调用。

and copy ExporterFactory.java from primefaces source. You can then replace the original PDFExporter call with your own implementation.

导出器实现公平简单。它使用iText库(虽然是过时的版本),您可以轻松地将其扩展到您的需求。

The exporter implementation is fairly simple. It uses iText library (although an outdated version) and you can easily extend it to your needs.

这种方法的一个明显问题是您可能需要格外小心何时(以及如果)您将来更新您的primefaces库。

An obvious problem with this approach is that you may have to be extra careful when (and if) you are updating your primefaces library in the future.

这篇关于在Primefaces中更改默认格式dataExporter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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