A.Casanova
A.Casanova

Reputation: 1017

PrimeFaces dataExport with lazy model return empty PDFs

I am using prime faces 13, with java 21 and the com.lowgie.itext v2.1.7 (It is the last one supported by prime faces).

The thing is that I can import my data correctly into others formats like cvs or xls, but it could be great to have the option of exporting a little section of users to pdf as well.

When I export my data as a pdf file, a pdf is downloaded but it is empty (0 Bytes file), and there is no error.

Here is my code:

<p:commandButton value="Export">
   <p:dataExporter type="pdf" target="table-id" fileName="myExportedPdf"/>
</p:commandButton>
                        
...

<p:dataTable id="table-id" var="data" value="#{ctrl.model}" reflow="true"
 multiViewState="true" draggableColumns="true" selection="#{ctrl.selection}"
 rowKey="#{data.id}" disabledSelection="#{data.disableSel}" paginator="true"
 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} 
 {PageLinks}   {NextPageLink} {LastPageLink}" rowsPerPageTemplate="10,25,50"
 rows="10" rowSelectMode="add" paginatorPosition="bottom" lazy="true"
 sortBy="#{crtl.defaultSort}" stripedRows="true"
>

I have search this in the official documentation of prime faces and also in the showcase official example.

As I am able to export the data with other formats, I think that it could be a problem with the itext dependency (that its obsolete), but if I upgrade that dependency, I get a ClassNotFound runtime error since the import path changes from com.lowgie to com.itext.

It could be a problem with the configuration? Or it is no longer possible to export data as pdf?

Upvotes: 2

Views: 367

Answers (1)

A.Casanova
A.Casanova

Reputation: 1017

I finally get the answer. PrimeFaces do not use the itext in its newer versions, you should remove all itext dependencies and use openpdf instead:

See the git repository or download the jar from maven central repository.

Dependency:

<!-- https://mvnrepository.com/artifact/com.github.librepdf/openpdf -->
<dependency>
  <groupId>com.github.librepdf</groupId>
  <artifactId>openpdf</artifactId>
  <version>1.3.40</version>
</dependency>

I get this dependency definition from the showcase git repository. If you need to export the data as a MS file, you can do it with poi, see the official pom file to get the full dependency list.

Upvotes: 4

Related Questions