How do I show U+0104 with openpdf?

62 Views Asked by At

I am trying to create a pdf using openPDF. If I try to print certain characters like Ą (U+0104) they are not shown on the pdf which is produced.

I have set the Chunk font to Times New Roman using a .ttf file. This file was taken from my system (I know I may need to work out licensing issues later), and I know it has a character for Ą.

FontFactory.register("font/system-times-new-roman.ttf", "custom");
Font font = FontFactory.getFont("custom");
Chunk chunk = new Chunk("Value to Print", font);

I can tell this is succesfully setting the font to Times New Roman, but not why it isn't showing some characters. I get the same if I set it using:

Font font = FontFactory.getFont("Times-Roman")

If I set the font to: Font font = FontFactory.getFont("defaultEmbedded") Then it shows the character, but not in a serif font. Has anyone come across this before? I could try using another pdf generator tool, but would require a lot of rework.

1

There are 1 best solutions below

0
Stephen On

As mentioned in the link K J sent, the issue is that the multi-byte characters were not showing. To enable them I added the Apache dependencies:

       <dependency>
           <groupId>org.apache.xmlgraphics</groupId>
           <artifactId>fop</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlgraphics</groupId>
            <artifactId>xmlgraphics-commons</artifactId>
            <version>2.3</version>
       </dependency>

I then updated the getFont call with this:

FontFactory.getFont("custom", "Identity-H", false, 10, 0, null)));

Now multi byte characters are displaying correctly in Times New Roman.