Export datatable to PDF

Asked

Viewed 193 times

1

I’m using Java,JPA,Primefaces,Wildfly, I have a datatable that I need to export to PDF,in excel just add the poi.jar that works but in PDF I don’t know which poi I should add, someone could help me?

1 answer

1

You can use the <p:dataExporter>:

<h:form>
    <p:dataTable id="tbl" var="car" value="#{dataExporterView.cars}">

        <f:facet name="{Exporters}">
            <h:commandLink>
                <p:graphicImage name="/demo/images/pdf.png" width="24"/>
                <p:dataExporter type="pdf" target="tbl" fileName="cars"/>
            </h:commandLink>
        </f:facet>

        <!-- colunas -->

    </p:dataTable>
<h:form>

You can export to many other formats, including XLS. Just change the property type for type=xls.


EDIT:

For the PDF export to work you must include the libraryiText in your project.

For the export to XLS to work you must include the library apache poi in your project.


More information on site of Primefaces.

  • This trexo is exactly like this on the site of the first faces,including I am using this way, but to use need a poi, I added this jar to take the Exel but not yours which is the PDF

  • 1

    From what I understand you need to add a lib call iText also.

  • Voce can tell me which version of this lib I should take as parameter?

  • 1

    Can be version 2.1.7

  • 1

    I got it, it worked, this is the right version, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.