We're sorry Aspose doesn't work properply without JavaScript enabled.

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

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.Document.convertInternal(Unknown Source)
at com.aspose.pdf.Document.convert(Unknown Source)


Has anyone experienced this issue?
What am I missing?

Best regards,
Daniel Serva

@danielserva

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

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

@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.

Hello,

i have similar error when i am trying to convert a PDF file to PDFA:

Caused by: java.lang.NullPointerException
at com.aspose.pdf.internal.l20if.l3if.lc(Unknown Source)
at com.aspose.pdf.internal.l9l.lk.lI(Unknown Source)
at com.aspose.pdf.internal.l9l.l0v.lI(Unknown Source)
at com.aspose.pdf.internal.l8f.ly.lI(Unknown Source)
at com.aspose.pdf.internal.l8f.ly.l0h(Unknown Source)
at com.aspose.pdf.internal.l8f.ly.lf(Unknown Source)
at com.aspose.pdf.internal.l8f.l0if.l0l(Unknown Source)
at com.aspose.pdf.internal.l8f.ly.lI(Unknown Source)
at com.aspose.pdf.Document.convert(Unknown Source)


PDF_Asset_Overview_Large.pdf (590.9 KB)

@xmedia

Would you please share the code snippet that you are using for conversion. We will test the scenario in our environment and address it accordingly.

Here is my code:

try (InputStream is = new BufferedInputStream(new FileInputStream(options.getInputFile()))) {
var logXml = options.getTempFile("xml");
var conversionOptions = new PdfFormatConversionOptions(logXml.toString(), PdfFormat.PDF_A_3B,
ConvertErrorAction.Delete);
var pdf = new com.aspose.pdf.Document(is);
pdf.convert(conversionOptions);
pdf.save(options.getOutputFile().getAbsolutePath());
}

@xmedia

We tested the scenario in our environment with Aspose.PDF for Java 20.5 and faced an out of memory exception. However, we have logged an issue as PDFJAVA-39456 in our issue tracking system along with the details which you have provided. We will further look into this and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.