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

1
Hi, I am trying to convert a PDF file to PDFA with the following code inside a Java Action and aspose.pdf version 19.6:     private ByteArrayOutputStream convertFile(MyDocument sourceFile) {         InputStream inputStream = Core.getFileDocumentContent(getContext(), sourceFile.getMendixObject());         Document pdfDocument = new Document(inputStream);         ByteArrayOutputStream out = new ByteArrayOutputStream();         ByteArrayOutputStream outPutLogStream = new ByteArrayOutputStream();         pdfDocument.convert(outPutLogStream, PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);         pdfDocument.save(out);         return out;     } However, the following line pdfDocument.convert(outPutLogStream, PdfFormat.PDF_A_1B, ConvertErrorAction.Delete); 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) Please note that the following almost identical code works perfectly fine when running in a Java “main” method outside Mendix: 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);   Has anyone experienced this issue? What am I missing? Best regards, Daniel Serva
asked
2 answers
0

Are you sure your file is available? If you only created it and did not commit it the contents might not be available on the disk. And therefore impossible to stream. Causing a nullpointer when the convert function tries to read the inputstream.

answered
0

I use this library in one of the projects that I work on. Haven’t run into this issue. I would put checks around your documents to make sure there are contents before trying to convert. The mendix file doc has an attribute called “hasContents” that you could use. Im not sure if there is an equivelant for the aspose document class. 

answered