Font problem with com.aspose.pdf.TextStamp

Hello Aspose Team,

i have a font problem when using com.aspose.pdf.TextStamp:





Document document = new Document(“test.pdf”);

Document stampDocument = new Document();

Page pdfPage;

int numberPages = document.getPages().size();

for (int i=0; i<numberPages; i++) {

// Get the page at a particular index of the Page Collection

pdfPage = document.getPages().get_Item(i+1);

// Stamp Header

TextStamp textStamp = new TextStamp(“Test Header with Font Arial”);

//set properties of the stamp

textStamp.setTopMargin(22);

textStamp.setHorizontalAlignment(HorizontalAlignment.Left);

textStamp.setVerticalAlignment(VerticalAlignment.Top);

TextState textState= textStamp.getTextState();

textState.setFont(FontRepository.findFont(“Arial”));

textState.setFontSize(12);

pdfPage.addStamp(textStamp);

// Add the page to the new document object

stampDocument.getPages().add(pdfPage);

}

stampDocument.save(“test-stamped.pdf”);

document.close();

stampDocument.close();





The new document will be generated, but if i try to show it with the Acrobat Reader, i only see dots in the Header and the following Dialog appears:

“Cannot find or create font “PIPWFM+Arial”. Some characters may not display or print correctly.”

What’s wrong?



With best regards

Frederic

Hi Frederic,

Thanks for your inquiry. We have tested the scenario and noticed the reported issue, so logged a ticket PDFNEWJAVA-34652 in our issue tracking system for rectification. We will notify you as soon as we resolve it.

Moreover, as a workaround, you may add pages once into a new PDF document after stamping the original PDF document (outside of the for loop) instead of adding pages one by one. It will help you to accomplish the task.

Document document = Document("Input.pdf");
Document stampDocument = new Document();

Page pdfPage; int numberPages = document.getPages().size();

For i=0 i<numberPages i++) // Get the page at a particular index of the Page Collection
{

    pdfPage = document.getPages().get_Item(i+1);
     //Stamp Header
    TextStamp textStamp = new TextStamp("Test Header with Font Arial");

    // set properties of the stamp
    textStamp.setTopMargin(22);
    textStamp.setHorizontalAlignment(HorizontalAlignment.Left);
    textStamp.setVerticalAlignment(VerticalAlignment.Top);
    TextState textState= textStamp.getTextState;
    textState.setFont(FontRepository.findFont("Arial"));
        textState.setFontSize(12);
        pdfPage.addStamp(textStamp);

     //Add the page to the new document object
   // stampDocument.getPages().add(pdfPage);

}

stampDocument.getPages().add(document.getPages());
stampDocument.save(myDir + "test-stamped.pdf");
document.close();
stampDocument.close();;

Best Regards,