ApplyPageStamp: Save Document- NullPointerException

Hello All,

I as using Aspose version 19.1 and I am trying to apply page stamp in the PDFs. But for some specific documents I am getting NullPointerException .However this happens only for few specific documents while for other it is working fine.Can anyone please suggest why I am getting NullPointerException during saving the document.

my java code looks like :

public void applyPageStamp(Document doc, String stamp) throws FNAException {
	Font font = FontRepository.findFont("Helvetica", true);
	PageCollection pages = doc.getPages();
	for (Page page : pages) {			
		writeToPage(font, fontSize, doc, page, stamp);
	}
}

private void writeToPage(Font font, float fontSize, Document doc,
		Page page, String text) throws FNAException {
	

	// create text stamp
	TextStamp textStamp = new TextStamp(text);

	int margin = 15;
		textStamp.setHorizontalAlignment(HorizontalAlignment.Right);
		textStamp.setVerticalAlignment(VerticalAlignment.Top);
		textStamp.setTopMargin(margin);
		textStamp.setRightMargin(margin);
		
	// set text properties
	textStamp.getTextState().setFont(font);
	textStamp.getTextState().setFontSize(fontSize);
	// add stamp to particular page
	page.addStamp(textStamp);
	// save output document
	**doc.save();**
}

ERROR:

 2019-03-19 13:20:54,875 [http-bio-8080-exec-9] ERROR (               CERestImpl:92) - Error
java.lang.NullPointerException
at com.aspose.pdf.internal.l8f.l0v.lv(Unknown Source)
at com.aspose.pdf.internal.l9p.ld.lI(Unknown Source)
at com.aspose.pdf.internal.l8f.l0p.lf(Unknown Source)
at com.aspose.pdf.internal.l8f.l0t.lj(Unknown Source)
at com.aspose.pdf.internal.l0k.l0if.lh(Unknown Source)
at com.aspose.pdf.ADocument.l1n(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at com.eurodyn.eips.fna.business.impl.AsposePDFServiceImpl.writeToPage(AsposePDFServiceImpl.java:812)
at com.eurodyn.eips.fna.business.impl.AsposePDFServiceImpl.applyPageStamp(AsposePDFServiceImpl.java:733)

@ashokkrb

We have responded to similar inquiry in other thread. You may please follow up there.

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