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);
	page.addStamp(textStamp);
	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)

samplePDF.pdf (27.6 KB)

@ashokkrb

We have responded to similar inquiry in other thread. You may please follow up there for further details. However, for the file which you have shared in this thread, we have logged a separate issue as PDFJAVA-38446 in our issue tracking system. We will surely let you know as soon as some additional updates are available about issue rectification. Please spare us little time.

We are sorry for the inconvenience.

Thank you Asad Ali for your response.
Thank you for the suggestion for saving the doc.I have modified the code for doc.save() .
As you are also able to replicate the issue with the Aspose, I am eagerly waiting for the help and support for the solution.
Thanks in advance .
Ashok

@ashokkrb

Thanks for your feedback.

We will definitely let you know as soon as some progress is made towards resolution of logged ticket. Please spare us little time.

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

Thank you for the help and support .Yes it is working fine with the latest version 19.3 .

@ashokkrb

Thanks for your kind feedback.

Please keep using our API and in case you have any other inquiry, please feel free to create a new topic.