Add non-English special character text in PDF using Aspose.PDF - text is not showing properly

Hi,
I would like to use the following:

public static void main(String[] args) throws UnsupportedEncodingException, DecoderException {
    // open document
    Document pdfDocument = new Document(inputFile);
    
    Page pdfPage = pdfDocument.getPages().get_Item(1);
    TextFragment textFragment = createTextFragment(pdfPage);
    pdfPage.getParagraphs().add(createFloatingBox(textFragment));
    
    // save updated PDF file
    pdfDocument.save(outputFile);
}

private static TextFragment createTextFragment(Page pdfPage) {
        String text = "This is some custom-text above the title.\n" +
        "10.11.2020 15:30\n" +
        "Fachidiot für traumatologies";            
        TextFragment textFragment = new TextFragment(text);
        return textFragment;
}

private static FloatingBox createFloatingBox(TextFragment textFragment) {
    FloatingBox box = new FloatingBox();
    box.setTop(Double.parseDouble("2") * 72);
    box.setLeft(Double.parseDouble("2") * 72);
    box.setHeight(Double.parseDouble("1") * 72);
    box.setWidth(Double.parseDouble("4") * 72);
    
    box.setHorizontalAlignment(HorizontalAlignment.Left);
    box.setVerticalAlignment(VerticalAlignment.Top);

    textFragment.setMargin(new MarginInfo(0, 0, 0, 0));
    box.getParagraphs().add(textFragment);
    return box;
}

When the text has an ‘ü’, the text is not shown at all on a PDF Page. If I change the ‘ü’ to ‘ue’, so the text is shown correctly? What should I do for having support to special characters?

I use Aspose.pdf for Java Version 20.9

best regards,

Igor

@igor.berchtold

Would you please make sure that necessary fonts are installed in your system. Please try to install Windows essential fonts and test the scenario again. In case you still face any issue, please let us know. We tested the scenario in our environment and did not notice any issue.

test.pdf (4.4 KB)

Hi Ali,

thank you for the quick reply. I will check it out with the fonts.

best regards,

Igor

yep it work. thank you for the hint.
best regards,
Igor

1 Like