Convert Docx to PDF generate an error

I have a Docx that i want to convert to PDF.
When i call the “new Document()”, i get the following error :

 Exception in thread "main" com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
 	at com.aspose.words.FileFormatUtil.zzWew(Unknown Source)
 	at com.aspose.words.Document.zzaQ(Unknown Source)
 	at com.aspose.words.Document.zzXDk(Unknown Source)
 	at com.aspose.words.Document.<init>(Unknown Source)
 	at com.aspose.words.Document.<init>(Unknown Source)
 	at testCP.testConvertDocxToPDF.main(testConvertDocxToPDF.java:20)
 Caused by: java.lang.NullPointerException: Cannot invoke "com.aspose.words.Section.getBody()" because the return value of "com.aspose.words.Document.getLastSection()" is null
 	at com.aspose.words.zz2A.zzXDk(Unknown Source)
 	at com.aspose.words.zz2A.zzWoU(Unknown Source)
 	at com.aspose.words.zz2A.zzHD(Unknown Source)
 	at com.aspose.words.zzWll.zzYuD(Unknown Source)
 	at com.aspose.words.zzWll.zzHD(Unknown Source)
 	at com.aspose.words.zzYVL.zzHD(Unknown Source)
 	at com.aspose.words.Document.zzaQ(Unknown Source)
 	... 4 more

Here is the test document :
test.docx (64.2 KB)

Here is the code used :

import com.aspose.words.Document;
import com.aspose.words.SaveFormat;

String input  = "C:\\temp\\docToPDF\\test.docx";
String output = "C:\\temp\\docToPDF\\test.pdf";

Document doc = new Document(input);
doc.save(output, SaveFormat.PDF);

The error happen only if i use the license aspose word.

Can someone take a look and help me to solve it? Please

@pkvogt

The error you are encountering, FileCorruptedException, indicates that the DOCX file you are trying to load may be corrupted or not in a valid format. Here are some steps you can take to troubleshoot and resolve this issue:

  1. Check the Document: Open the DOCX file in Microsoft Word or another compatible word processor to see if it opens without any issues. If it does not open, the file may indeed be corrupted.

  2. Recreate the Document: If the document is corrupted, try recreating it from scratch or using a backup version if available.

  3. Verify License Application: Since you mentioned that the error occurs only when using the Aspose license, ensure that the license is correctly applied in your code. Double-check the license application code to confirm it is set up properly.

  4. Check for Updates: Ensure that you are using the latest version of Aspose.Words, as updates may include bug fixes and improvements that could resolve your issue.

  5. Contact Support: If none of the above solutions work, consider reaching out to Aspose support with the problematic document for further assistance.

If you can provide more details about the document or any specific changes made before the error occurred, I may be able to offer more targeted advice.

  1. Check the Document

It open correctly with Word

  1. Verify License Application

The license are correctly set. It work correctly with other Docx document

  1. Check for Updates

I use Aspose word 25.8

@pkvogt
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-28630

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.

Hi @alexey.noskov ,

It seems that you have closed your internal ticket : WORDSNET-28630.
Does this mean that a fix will be deliver with the next version of Apose.word?

Note : I have tested with the version 25.9 and i still have the same issue.

@pkvogt Yes, we have already resolved the problem. The fix will be included into the next 25.10 version of Aspose.Words. We will keep you informed and let you know once it is released.

1 Like