2013-05-15 1 views
1

데이터 테이블의 pdf를 생성하기 위해 dataexporter를 사용하고 있습니다. 데이터 테이블에서 열 헤더가 중앙화되어 있지만 같은 열의 pdf 버전은 왼쪽에 정렬되어 있습니다. 어떻게 pdf의 열을 데이터 테이블처럼 중앙화 할 수 있습니까?Dataexporter pdf header position

답변

2

나는 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); 
} 

}

는 콩 : 내 페이지에서

public void exportPDF(DataTable table, String filename) throws IOException { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    Exporter exporter = new CustomPDFExporter(); 
    exporter.export(context, table, filename, false, false, "iso-8859-1", null, null); 
    context.responseComplete(); 
} 

내가 추가 :

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