Since the jasper report uses the itext library - the easiest way to check if the font is displayed correctly in pdf is to check it directly using itext.
Example program * adapted from iText: Chapter 11: Choosing the right font
import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Font; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.ColumnText; import com.lowagie.text.pdf.PdfWriter; public class FontTest { public static final String RESULT = "fontTest.pdf"; public static final String TEST = "Test to render this text with the turkish lira character \u20BA"; public void createPdf(String filename) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); BaseFont bf = BaseFont.createFont( "pathToMyFont/myFont.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font = new Font(bf, 20); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(36, 730, 569, 36); column.addElement(new Paragraph(TEST, font)); column.go(); document.close(); } public static void main(String[] args) throws IOException, DocumentException { new FontTest().createPdf(RESULT); } }
Some notes (see example):
- To display special characters, use the example of the encoded value
\u20BA to avoid problems with the encoding type in your file. - Consider always using Unicode encoding, this is the recommended approach in the new PDF standard (PDF / A, PDF / UA) and allows different types of encoding, with the only drawback a slightly larger file size.
Output:
If your font displays correctly in font.est.pdf, you have a problem with your font extensions in the jasper report.
If the font does not display correctly in font.est.pdf, you cannot do anything in jasper reports, you need to find a different font.
* The latest jasper-reports distribution uses a special version of itext-2.1.7, import in this version of com.lowagie.text , if you use a later version, import com.itextpdf.text , as in the adapted example.
Petter Friberg Feb 01 '16 at 10:17 2016-02-01 10:17
source share