I have added a DataExporter. If the data grid has Arabic letters, they are not being deployed at all, or they are being displayed disjoint and above each other. Here is an image:
To solve the issue, I have added PDFOption, including a new Arial
font.
pdfOpt = new PDFOptions();
InputStream fontStream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/resources/fonts/arial.ttf");
BaseFont baseFont = null;
try {
baseFont = BaseFont.createFont("arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, fontStream.readAllBytes(), null);
} catch (IOException ex) {
Logger.getLogger(PrimefacesPDFExporterOptions.class.getName()).log(Level.SEVERE, null, ex);
} catch (DocumentException ex) {
Logger.getLogger(PrimefacesPDFExporterOptions.class.getName()).log(Level.SEVERE, null, ex);
}
Font font = new Font(baseFont, 12, Font.NORMAL);
pdfOpt.setFontName(font.getBaseFont().getFullFontName()[0][3]);
The problem with this solution is that I am not being able to set the font it self, just the name of it. So, I need to set the encoding. To do that, I added encoding attribute to the p:dataExporter
and set the value to Identity-H
:
<p:dataExporter options="#{primefacesPDFExporterOptions.pdfOpt}" encoding="Identity-H" type="pdf" preProcessor="#{primefacesPDFExporterOptions.makePDFLandscape}" pageOnly="false" target="explorerResultsTableId" fileName="data"/>
This did not solve the issue!
Another option I am trying to apply, is to change the font of every cell in the PDF to the created one. But I am not able to get the cells!