Primefaces PDFExporter displaying Non ASCII letters as junk in the PDF

Viewed 133

Using PrimeFaces 6.0 PDFExporter to export data-table data to PDF.

Using below code for export:

DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent(":contactListform:contactDataTable");
FacesContext context = FacesContext.getCurrentInstance();
com.lowagie.text.Document document = new com.lowagie.text.Document();
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

com.lowagie.text.pdf.PdfWriter.getInstance(document, baos);          

document.add(exportPDFTable(context, dataTable, false, false, "UTF-8"));
document.close();
writePDFToResponse(context.getExternalContext(), baos, filename);  

Issue: Non ASCII letters (For example Chinese letters ) are displaying as question mark symbol (????) in PDF.

1 Answers

See this ticket for the fix: https://github.com/primefaces/primefaces/issues/3585

PF 8.0 or higher allows you to set the Font of the PDF and you have to pick a font that supports the Chinese characters.

PDFOptions pdfOpt = new PDFOptions();
pdfOpt.setFontName("Courier");

Obviously "Courier" does not but I am sure you have a font that supports Chinese characters you can set it to?

Related