Answer the question
In order to leave comments, you need to log in
How to export to pdf dataTable (problem with encoding and font)?
Hello,
the problem is in exporting the table to pdf format.
<h:commandLink>
<p:graphicImage value="../../images/pdf.png" width="30"/>
<p:dataExporter type="pdf" target="roadTable" fileName="road" pageOnly="true" encoding="cp1251"/>
</h:commandLink>
Document doc= (Document) document;
Font font = FontFactory.getFont("C:\\Windows\\Fonts\\times.ttf", "Cp1251", BaseFont.EMBEDDED);
BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\times.ttf", "Cp1251", true);
doc.open();
Answer the question
In order to leave comments, you need to log in
It can be useful to someone, I solved this problem like this:
the encoding is "CP1251", there are letters, but all are "stuck together". The problem is in the font. To change the font, you need to rewrite the PDFExporter library class. To do this, we create the org.primefaces.component.export package and create the PDFExporter class in it. We find the source on github and copy it to this file. There is a line in the exportPDFTable method:
private String tahoma="C:\\Windows\\Fonts\\tahoma.ttf";
.........
this.cellFont = FontFactory.getFont(tahoma, string1);
this.facetFont = FontFactory.getFont(tahoma, string1, Font.DEFAULTSIZE, Font.BOLD);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question