Free Support Forum - aspose.com

Alignment of punctuation in Japanese texts

Hello forum, hello support,

we experience an effect where the PDF result differs from the input - it’s the vertical alignment of punctuation like commas or full stops.

According to resources like wikipedia, when aligned horizontally, in Japanese writing those characters should be bottom aligned vertically. But in the output that we create with Aspose PDF from scratch, they are centered.
This happens specifically in combination with the NotoSansCJK font.

Here is a code example that works (without NotoSansCJK font):

    Document document = new DocumentFactory().createDocument();
    Page page = document.getPages().add();
    page.setPageSize(597.6, 842.4);

    FloatingBox topFloatingBox = new FloatingBox();
    topFloatingBox.setTop(85);

    TextFragment proposal = new TextFragment("エコモ二。");
    proposal.getTextState().setFontStyle(FontStyle.CjkFont);
    proposal.getTextState().setCharacterSpacing(5f);
    proposal.getTextState().setFontSize(PdfStyles.PROPOSAL_FONT_SIZE);
    proposal.setHorizontalAlignment(HorizontalAlignment.Center);

    topFloatingBox.getParagraphs().add(proposal);
    page.getParagraphs().add(topFloatingBox);

    document.save("result1.pdf");

result1.pdf (121.5 KB)

But if we want to use NotoSansCJK (as we don’t know in the real application whether the text will be Asian or western), the dot is not bottom aligned anymore:

    Document document = new DocumentFactory().createDocument();
    Page page = document.getPages().add();
    page.setPageSize(597.6, 842.4);

    FloatingBox topFloatingBox = new FloatingBox();
    topFloatingBox.setTop(85);

    TextFragment proposal = new TextFragment("エコモ二。");
    proposal.getTextState().setFont(FontRepository.openFont("<path to NotoSansCJKTCRegular.otf>"));
    proposal.getTextState().setCharacterSpacing(5f);
    proposal.getTextState().setFontSize(PdfStyles.PROPOSAL_FONT_SIZE);
    proposal.setHorizontalAlignment(HorizontalAlignment.Center);

    topFloatingBox.getParagraphs().add(proposal);
    page.getParagraphs().add(topFloatingBox);

    document.save("result2.pdf");

result2.pdf.png (5.6 KB)
(The PDF itself is very large due to the included NotoSansFont, that’s why I created a screenshot instead.)

Can you help us with this problem? Our customers regard this as a problem and we don’t feel like we can help them without your support?

Kind regards,
Stefan

@stefan.raubal

We tested the scenario in our environment while using your code snippet with Aspose.PDF for Java 21.3 and did not notice any issue. Please check the attached output PDF for your kind reference. Could you please try using the latest version of the API and let us know in case issue still persists.

Hi Ali,

thanks for the quick reply - looks good.
We will upgrade and test in our environment.

Kind regards,
Stefan

@stefan.raubal

Sure, please take your time to test the scenario using the latest version and let us know in case you face any issue.