java.lang.NullPointerException when using com.aspose.pdf.Document to convert to PDFA


#1

Hello,
I am trying to convert a PDF file to PDFA with the following code in Java 8 and aspose.pdf version 19.6:

	File myFile = new File("C:\\foo.pdf");
	InputStream inputStream = new FileInputStream(myFile);
	FileOutputStream out = new FileOutputStream("C:\\bar.pdf");
	Document pdfDocument = new Document(inputStream);
	ByteArrayOutputStream outPutLogStream = new ByteArrayOutputStream();
	pdfDocument.convert(outPutLogStream, PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);

However, the last line is giving me the following error message:

java.lang.ExceptionInInitializerError: null
at com.aspose.pdf.internal.l71y.lt.lj(Unknown Source)
at com.aspose.pdf.internal.l71y.lt.lI(Unknown Source)
at com.aspose.pdf.internal.l71y.lt.<clinit>(Unknown Source)
at com.aspose.pdf.internal.ms.System.l4u.<clinit>(Unknown Source)
at com.aspose.pdf.internal.ms.System.IO.l3v.<init>(Unknown Source)
at com.aspose.pdf.internal.ms.System.IO.l3v$lI.<init>(Unknown Source)
at com.aspose.pdf.internal.ms.System.IO.l3v.<clinit>(Unknown Source)
at com.aspose.pdf.internal.l71h.l46v.<init>(Unknown Source)
at com.aspose.pdf.ADocument.convertInternal(Unknown Source)
at com.aspose.pdf.Document.convertInternal(Unknown Source)
at com.aspose.pdf.ADocument.convert(Unknown Source)
at com.aspose.pdf.Document.convert(Unknown Source)

And the following " caused by":

Caused by: java.lang.NullPointerException: null
at com.aspose.pdf.internal.l71y.lf$lI.<init>(Unknown Source)
at com.aspose.pdf.internal.l71y.lf.<clinit>(Unknown Source)
at com.aspose.pdf.internal.l71y.lt.lj(Unknown Source)
at com.aspose.pdf.internal.l71y.lt.lI(Unknown Source)
at com.aspose.pdf.internal.l71y.lt.<clinit>(Unknown Source)
at com.aspose.pdf.internal.ms.System.l4u.<clinit>(Unknown Source)
at com.aspose.pdf.internal.ms.System.IO.l3v.<init>(Unknown Source)
at com.aspose.pdf.internal.ms.System.IO.l3v$lI.<init>(Unknown Source)
at com.aspose.pdf.internal.ms.System.IO.l3v.<clinit>(Unknown Source)
at com.aspose.pdf.internal.l71h.l46v.<init>(Unknown Source)
at com.aspose.pdf.ADocument.convertInternal(Unknown Source)
at com.aspose.pdf.Document.convertInternal(Unknown Source)
at com.aspose.pdf.ADocument.convert(Unknown Source)
at com.aspose.pdf.Document.convert(Unknown Source)

Has anyone experienced this issue?
What am I missing?

Best regards,
Daniel Serva


#2

@danielserva

Would you please share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.


#3

Hi Asad.ali, thank you for your reply,
The issue happens with any PDF, it’s not file related. We have tracked down the problem to this:

Caused by: java.lang.ExceptionInInitializerError: null
at com.aspose.pdf.internal.p838.z4.m3(Unknown Source)
at com.aspose.pdf.internal.p838.z4.m1(Unknown Source)
at com.aspose.pdf.internal.p838.z4.(Unknown Source)
at com.aspose.pdf.internal.ms.System.z67.(Unknown Source)
at com.aspose.pdf.Document.m2(Unknown Source)
at com.aspose.pdf.Document.getLocalFontPaths(Unknown Source)
at com.aspose.pdf.internal.p69.z17.m12(Unknown Source)
at com.aspose.pdf.internal.p69.z17.m9(Unknown Source)
at com.aspose.pdf.internal.p69.z17.m8(Unknown Source)
at com.aspose.pdf.internal.p69.z17.m1(Unknown Source)
at com.aspose.pdf.FontRepository.getSources(Unknown Source)

We have a cloud environment that doesn’t allow the library to access the filesystem, so we followed the instructions on this link:

But we are still getting the error.
Would you know how can we make this without the library calling “com.aspose.pdf.Document.getLocalFontPaths()”? We believe this method is somehow trying to access the filesystem and causing our issue.

Best regards,
Daniel Serva


#4

@danielserva

getLocalFontPaths() and setLocalFontPaths() methods are used to load installed fonts which API needs to perform certain operations e.g. Conversion, PDF Generation, etc. In case you do not use these methods, the API will load fonts from default font folder. You may please try conversion process without calling these methods and let us know in case you face any issue.

Furthermore, would you please share complete environment details where API methods are running. This would help us understanding the issue and proceed further to assist you accordingly.