2
votes

I have created a font extension in Jasper for noto-sans font (https://www.google.com/get/noto/#sans-lgc) and have added it to my classpath. And my application need to support fr, de, ja, ko, zh_CN, zh_TW, es ,en. But the generated pdf is not rendering (ja, ko, zh_CN, zh_TW). then I tried spliting the problem between jasper and itext so I tried with below program to check if iText is working correctly.

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 Itext_test {

/** The resulting PDF file. */
public static final String RESULT = "fontTest.pdf";
/** the text to render. */
public static final String TEST = "사과-korean, 苹果(Chienses-simplified), 蘋果(Chinese-traditional), 林檎(Japanese), Sebastián(Spanish), ADÉLAÏDE-fr(French), James Bond(English)";

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(
        "NotoSans-Regular.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 Itext_test().createPdf(RESULT);
}
}

Below is the out pdf screenshot enter image description here

So as we can see ja, ko, zh_CN, zh_TW chars are not being rendered. I am using jaspersoft Studio to create the .jrxml file and populating it by java code. for more detail please checkout this question Unicode characters in Jasper Report I don't know where and what to look for.
I would be very greatful if somebody could point out the error or put me in right direction...

1
@DaveJarvis, I tried putting the unicode instead of characters by following the guide and also tried with various pdf encoding but still no luck :(user6385735

1 Answers

-1
votes

It's mainly because OracleJRE is a commercial JRE,but Noto fonts are distributed under an open-source license and using OTF format, so Oracle JRE won't support these fonts(as long as other OTF fonts).

What I did is to convert the OTF to TTF format, and Oracle JRE can read and use them.

By the way, if you use OpenJDK, you may use OTF fonts directly.