Document save throws null pointer exception while applying TextStamp


We get null pointer exception for few docs while trying to apply textstamp (fontsize=10) iteratively for each page at the line where we call save() method of com.aspose.pdf.Document

Font font = FontRepository.findFont("Helvetica", true);
PageCollection pages = doc.getPages();
for (Page page : pages) {
	writeToPage(font, fontSize, doc, page, stamp);
//writeToPage code snippet
TextStamp textStamp = new TextStamp(text);
int margin = 15;
// Set text alignment and margin based on page rotation

// set text properties
// add stamp to particular page

// save output document;

at 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.inteyrnal.l8f.l0t.lj(Unknown Source)
at com.aspose.pdf.internal.l0k.l0if.lh(Unknown Source)
at com.aspose.pdf.ADocument.l1n(Unknown Source)
at Source)
at Source)

Here are more details about the env where Aspose is integrated in.
The Aspose related services are exposed as REST calls packaged as web application
with the rest of the other services specific to project.

Oracle JDK 1.7.0_71
Jai_Codec 1.1.3
Springframework 4.0.1.RELEASE
Tomcat 7.0.39
RHEL 6.5

Best regards,
MansoorTest-A.pdf (37.0 KB)


Thanks for contacting support.

We have tested the scenario in our environment while using your code snippet and were able to replicate the issue. However, we modified code snippet a little bit by taking statement out of iteration. It is recommended and right approach to save document once after processing because once it is saved, it closes all initialized resources along with itself.

Furthermore, we have also observed that if we save PDF document as separate file, the issue does not occur. saved.pdf (38.2 KB) Regarding the issue, we have logged it as PDFJAVA-38445 in our issue tracking system for further investigation. We will look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

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