Add Text Stamp in PDF using Java with 4 byte characters - Aspose.PDF

Using PDF for Java version 20.7 when stamping text that contains 4 byte characters in it regardless of the system’s encoding or font used it shows as boxes instead of the character.

Code:

public static void main(String[] args) {
String inPdf = “test.pdf”;
String outPdf = “test_after.pdf”;
FormattedText formattedText = new FormattedText();
formattedText.addNewLineText(“:chart_with_upwards_trend::golf::fuelpump::church:𠝹𠝹𠱓𠱓𠱸𓆣:adult::child::older_adult::bearded_person::person_in_steamy_room::person_climbing::person_in_lotus_position::mage::fairy::vampire::mermaid::elf::genie::zombie:”);
TextStamp textStamp = new TextStamp(formattedText);
textStamp.setHorizontalAlignment(HorizontalAlignment.Center);
textStamp.setVerticalAlignment(VerticalAlignment.Top);

Document document = new Document(inPdf);

for (Page page : document.getPages()) {
    page.addStamp(textStamp);
}
document.save(outPdf);

}

Test file(but any pdf should work): test.pdf (7.6 KB)
Example: image.png (6.9 KB)

Should note I tried this without using FormattedText as well to see if that was the problem and just using TextStamp with a string value directly still has the same problem.

TextStamp textStamp = new TextStamp(“:chart_with_upwards_trend::golf::fuelpump::church:𠝹𠝹𠱓𠱓𠱸𓆣:adult::child::older_adult::bearded_person::person_in_steamy_room::person_climbing::person_in_lotus_position::mage::fairy::vampire::mermaid::elf::genie::zombie:”);

Just noticed there is a newer version out of PDF so tried it (20.9) same results.

Just tried with some 3-byte UTF-8 characters and some are also failing. This string which contains only 3-byte characters instead of 4-byte.

TextStamp textStamp = new TextStamp(“₩¥豈ༀ:alarm_clock::stopwatch::timer_clock::hourglass_flowing_sand::umbrella:”);

has some hit or miss values in it:
image.png (1.9 KB)

@mstandfuss

We were able to replicate the issue in our environment while testing the scenario with Aspose.PDF for Java 20.9 and logged it as PDFJAVA-39787 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali can you provide any update to this bug?

Thanks

@mstandfuss

The ticket has been logged in our issue management system recently and we are afraid that it is pending for an investigation. It will be reviewed and resolved on a first come first serve basis. We will surely inform you as soon as we have some definite updates regarding its resolution. Please have patient and give us some time.

We are sorry for the inconvenience faced.

The issues you have found earlier (filed as PDFJAVA-39787) have been fixed in Aspose.PDF for Java 21.1.