Hi,
I am currently using:
- gradle:
-
implementation(group: 'com.aspose', name: 'aspose-pdf', version: '22.12')
-
implementation(group: 'com.aspose', name: 'aspose-words', version: '17.2.0')
- java: openjdk 11
- windows 10
- jboss eap 7.4.8
My problem i get an exception when i try to convert a docx file to a pdf file. The exception:
Caused by: java.lang.NullPointerException
at com.aspose.pdf.ADocument.preSave(Unknown Source)
at com.aspose.pdf.ADocument.lf(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at com.aspose.pdf.ADocument$4.lI(Unknown Source)
at com.aspose.pdf.internal.l89u.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l89u.lj.lI(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
This exception happens only to the docx file i attached to this thread. Other docx files seemed to work. xxxxxx1.docx (22.4 KB)
The code:
private ByteArrayOutputStream ladeWordAndAddToDocument(final InputStream dateiDatenStream, final com.aspose.pdf.Document ergebnisDoc) throws Exception { ByteArrayInputStream pdfByteInputStream = null; try (ByteArrayOutputStream pdfOutStream = new ByteArrayOutputStream();) { final com.aspose.words.Document asposeEinzufuegendesDocument = new com.aspose.words.Document( dateiDatenStream); asposeEinzufuegendesDocument.save(pdfOutStream, SaveFormat.PDF); pdfByteInputStream = new ByteArrayInputStream(pdfOutStream.toByteArray()); com.aspose.pdf.Document pdfDocument = new Document(pdfByteInputStream); final PageCollection pageCollection = pdfDocument.getPages(); ergebnisDoc.getPages().add(pageCollection); ByteArrayOutputStream output = new ByteArrayOutputStream(); ergebnisDoc.save(output); return output; } finally { if (pdfByteInputStream != null) { pdfByteInputStream.close(); } } }
Can you tell me why i am getting a NullpointerException, because other files are working.
The same error happens also to some pdf files, when i try to get a byte[] of a pdf file
pdf file which throws the same error.
Thanks