数据导出器pdf标题位置

数据导出器pdf标题位置,pdf,primefaces,data-export,Pdf,Primefaces,Data Export,我使用dataexporter创建数据表的pdf,在我的数据表中,列的标题是集中的,但是相同列的pdf版本是向左对齐的。如何使pdf的列像数据表一样集中。您的答案已经在stackoverflow上了: 还可以看看这里:如何使用Primefaces的exportProcessor 简而言之,您需要创建自己的处理器来创建自定义PDF我使用该解决方案来自定义PDFExporter,它工作得非常好,感谢您的关注。以下是我如何做到的: 我的自定义类: public class CustomPDFExpor

我使用dataexporter创建数据表的pdf,在我的数据表中,列的标题是集中的,但是相同列的pdf版本是向左对齐的。如何使pdf的列像数据表一样集中。

您的答案已经在stackoverflow上了:

还可以看看这里:如何使用Primefaces的exportProcessor


简而言之,您需要创建自己的处理器来创建自定义PDF

我使用该解决方案来自定义PDFExporter,它工作得非常好,感谢您的关注。以下是我如何做到的:

我的自定义类:

public class CustomPDFExporter extends PDFExporter {

@Override
protected void addColumnFacets(DataTable table, PdfPTable pdfTable, ColumnType columnType) {
    for(UIColumn col : table.getColumns()) {
        if(!col.isRendered()) {
            continue;
        }

        if(col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyModel();
        }

        if(col.isExportable()) {
           addHeaderValue(pdfTable, col.getFacet(columnType.facet()), FontFactory.getFont(FontFactory.TIMES, "iso-8859-1", Font.DEFAULTSIZE, Font.BOLD));
        }
    }
}

protected void addHeaderValue(PdfPTable pdfTable, UIComponent component, Font font) {
   String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component);

   PdfPCell cell = new PdfPCell(new Paragraph(value, font));
   cell.setHorizontalAlignment(Element.ALIGN_CENTER);
   pdfTable.addCell(cell);
}
}

豆子:

在我的页面中,我添加了:

<h:commandLink action="#{boxBean.exportPDF(boxTable, 'relatorio_caixas')}" >
     <p:graphicImage value="/resources/img/pdf.png"/> 
</h:commandLink>

<h:commandLink action="#{boxBean.exportPDF(boxTable, 'relatorio_caixas')}" >
     <p:graphicImage value="/resources/img/pdf.png"/> 
</h:commandLink>