Hello
With Aspose words 18.2 I have a NullPointerException when trying to convert a docx to pdf.
Problem occurs when a part of my docx is splitted into 2 pages
Stack trace :
Exception in thread "main" java.lang.NullPointerException: Cannot read field "zzYrz" because the return value of "com.aspose.words.zzZ4I.zztl()" is null
at com.aspose.words.zzX.zzZ(Unknown Source)
at com.aspose.words.zzX.zzZ(Unknown Source)
at com.aspose.words.zzYZ6.zzZ(Unknown Source)
at com.aspose.words.zzXK.zztA(Unknown Source)
at com.aspose.words.zzXK.zzY(Unknown Source)
at com.aspose.words.zzZ8A.zzZvi(Unknown Source)
at com.aspose.words.zzZ8A.zzS(Unknown Source)
at com.aspose.words.zzZ7M.zzJ(Unknown Source)
at com.aspose.words.zzYX7.zzn(Unknown Source)
at com.aspose.words.zz99.zzJ(Unknown Source)
at com.aspose.words.zz9A.zz5g(Unknown Source)
at com.aspose.words.zzZN0.zzZ(Unknown Source)
at com.aspose.words.Document.updatePageLayout(Unknown Source)
at com.aspose.words.Document.zzXA(Unknown Source)
at com.aspose.words.Document.getPageCount(Unknown Source)
at com.aspose.words.zz0L.zzZ(Unknown Source)
at com.aspose.words.zzZHN.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
at bug.Bug.generatePdf(Bug.java:24)
at bug.Bug.main(Bug.java:15)
Code and files used to reproduce :
package bug;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import com.aspose.words.SaveOptions;
public class Bug {
public static void main(final String[] args) throws Exception {
generatePdf("ok.docx", "ok.pdf");
generatePdf("fail.docx", "fail.pdf");
}
private static void generatePdf(final String docx, final String pdf) throws Exception {
Path file = Path.of(docx);
try (InputStream input = Files.newInputStream(file);
OutputStream output = Files.newOutputStream(Path.of(pdf));) {
Document doc = new Document(input);
SaveOptions so = SaveOptions.createSaveOptions(SaveFormat.PDF);
doc.save(output, so);
}
;
}
}
The 2 followings docx are the same. fail.docx
only contains extra blanck line in order to move content to the second page
ok.docx (135.4 KB)
fail.docx (135.4 KB)
PS : unfortunately, I cannot upgrade to newer version of Aspose because newer versions generate inconsistency in some docx used by our customers.
Thx
@kehrmit
It seems you are encountering a NullPointerException
when trying to convert a DOCX file to PDF using Aspose.Words version 18.2. This issue appears to occur specifically when the content of your DOCX file is split across two pages, which may indicate a problem with how the document is being processed during the conversion.
Here are a few steps you can take to troubleshoot and potentially resolve this issue:
-
Check Document Structure: Ensure that the DOCX file does not contain any corrupt elements or unsupported features that might cause issues during conversion. You can try simplifying the document by removing complex formatting or elements that may not be well-supported.
-
Use SaveOptions: When saving the document, you can specify SaveOptions
to control the conversion process. For example, you might want to try using different PdfSaveOptions
to see if that affects the outcome. Here’s a basic example of how to set up PdfSaveOptions
:
SaveOptions saveOptions = SaveOptions.createSaveOptions(SaveFormat.PDF);
// You can customize saveOptions here if needed
doc.save(output, saveOptions);
-
Test with Different Documents: Since you mentioned that fail.docx
only contains an extra blank line, try testing with other variations of the document to see if the issue persists. This can help identify if the problem is specific to the content or structure of the fail.docx
.
-
Review Stack Trace: The stack trace indicates that the error occurs during the layout update phase. This might suggest that the document’s layout is not being calculated correctly. If possible, try to isolate the part of the document that causes the issue and see if removing it resolves the problem.
-
Consider Upgrading: While you mentioned that upgrading is not an option due to inconsistencies with customer documents, it may be worth testing the latest version of Aspose.Words in a controlled environment to see if the issue has been resolved in newer releases.
If these steps do not resolve the issue, consider reaching out to Aspose support with the specific details of your documents and the error message for further assistance.
If you have any additional questions or need further clarification, feel free to ask!
PS : With the latest version 25.4, the CPU goes up to 100% and the conversion never seems to finish (I kill the process after few seconds). And that’s even with the ok.docx
file.
@kehrmit
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28211
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.