com.aspose.words.FileCorruptedException when opening docx file

Hi there,


I’m trying to open a word document and convert to pdf file using something like below:

Document doc = new Document(sourcedocpath);
doc.save(destination + “/” + filename+ “.pdf”);

It works great for .doc files and some of the .docx files, but in some .docx files I got a FileCorruptedException in the first line. Error details as follows:
com.aspose.words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
at com.aspose.words.FileFormatUtil.a(Unknown Source)
at com.aspose.words.Document.b(Unknown Source)
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
at com.aspose.words.Document.(Unknown Source)
Caused by: java.lang.NullPointerException
at com.aspose.words.afg.b(Unknown Source)
at com.aspose.words.ih.Ou(Unknown Source)
at com.aspose.words.ih.Ot(Unknown Source)
at com.aspose.words.ih.e(Unknown Source)
at com.aspose.words.ih.b(Unknown Source)
at com.aspose.words.ih.a(Unknown Source)
at com.aspose.words.gp.NA(Unknown Source)
at com.aspose.words.gq.read(Unknown Source)
at com.aspose.words.hp.NB(Unknown Source)
at com.aspose.words.hp.read(Unknown Source)
at com.aspose.words.Document.b(Unknown Source)
… 4 more

I have a couple of docx files that come from different sources that all encounter this issue, so I don’t think it’s something with a specific file itself. All these docx files open fine in MS Word so I’m not sure why some of these are working and some are not. I have attached one of the file that’s not working. I’m using the Aspose Words 15.8.0 version.

Any help would be appreciated.

Thanks! YZ
Hi Yanyan,

Thanks for your inquiry. After an initial test with Aspose.Words 15.8.0, I was unable to reproduce this issue on my side (please see attached 15.8.0-awjava.pdf).

Please make sure you have attached the correct document with your last post. To make sure, please download this file from here and try loading it with Aspose.Words for Java and see if it is still reproducible. If not then please attach the correct document here for testing.

Best regards,

Thank you for the respond. It turned out that I still have an old version of aspose words in my libraries so it wasn’t actually using the 15.8.0 one. Works fine now. Thanks!

Hi Yanyan,

It is great that the latest version resolves this issue. Please let us know any time you have any further queries.

Best regards,