PDF Java: Characters changed in stamp

Binary_View_of_input_and_output_strings.png (121.3 KB)
input.pdf (85.8 KB)
output.pdf (283.5 KB)

Aspose Team,

We use the Aspose PDF java package to add stamps to each page of PDF files and found out that some characters are changed in the label of the stamp.

Following is the sample code that reproduces the problem and attached are the input and output pdf files.

The input string for the label is as follows. See the attached picture for the binary view.

and the output string in the label of the output pdf file is as follows (copied from the output pdf file that is opened with Adobe Acrobat Reader DC). See the attached picture for the binary view.

Note that some characters in the output string are different from that in the input string (check with the binary views).

The operating system is Ubuntu 18.04. Java version is 1.8. Aspose PDF java package is 21.6.

import com.aspose.pdf.*;
import com.aspose.pdf.facades.FormattedText;
import com.aspose.pdf.facades.PdfFileEditor;
import java.util.ArrayList;
import java.util.List;

public class TestStamp {
public static void main(String[] args) {
try {

        String inPath = "/home/ubuntu/testdirs/testdir_stamp_chars/input.pdf";
        String outPath = "/home/ubuntu/testdirs/testdir_stamp_chars/output.pdf";
        String ucStr = "S3CbwktvZdqTPAj8f紲吹蹮ヨ糖㒟񆔒ᡌ!kohyfXibc";
        String llStr = "1";
        String lrStr = "YAX.PC.00000198";
        String fontFamily = "DejaVu Sans";
        Font font = FontRepository.findFont(fontFamily);;
        int fontSize = 10;

        // Stamps
        List<TextStamp> stampsToAdd = new ArrayList<>();
        // Uper Center
        stampsToAdd.add(convertToStamp(ucStr, HorizontalAlignment.Center, VerticalAlignment.Top, font, fontSize));
        // Lower Left
        stampsToAdd.add(convertToStamp(llStr, HorizontalAlignment.Left, VerticalAlignment.Bottom, font, fontSize));
        // Lower Right
        stampsToAdd.add(convertToStamp(lrStr, HorizontalAlignment.Right, VerticalAlignment.Bottom, font, fontSize));

        // Resize the page before adding the stamps
        int leftMargin = 0;
        int rightMargin = 0;
        int topMargin = 10;
        int bottomMargin = 10;
        PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(

        PdfFileEditor editor = new PdfFileEditor();
        Document document = new Document(inPath);
        editor.resizeContentsWithNormalization(document, parameters);

        for (Page page : document.getPages()) {
            for(TextStamp stamp : stampsToAdd){

    catch(Exception ex) {

private static TextStamp convertToStamp(String text, int horizontalAlignment, int verticalAlignment,
                                        Font font, int fontSize) {
    FormattedText formattedText = new FormattedText();
    TextStamp textStamp = new TextStamp(formattedText);
    return textStamp;



We have replicated the similar issue in our environment and have logged it as PDFJAVA-40629 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 is there any update on this?


We are afraid that the earlier logged ticket could not get resolved due to other pending issues in the queue. We will surely inform you as soon as we have definite updates about issue fix. Please be patient and spare us some time.

We are sorry for the inconvenience.