We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

WordToPDF produces damaged PDF

Hi,

I'm trying to convert my Word to PDF code from using Aspose.PDF to using the new .WordToPDF method.

When I save the attached Word document to PDF using the new .WordToPDF method to a MemoryStream (and then save it to the DB), I get the attached PDF. Opening the PDF, Adobe Reader gives the following message:

"There was an error opening this document. The file is damaged and could not be repaired."

If I use the old method with Aspose.PDF, it works fine.

The code I use to convert the Word document is:

Dim stream As New IO.MemoryStream

masterDoc.SaveToPdf(0, masterDoc.PageCount, stream, Nothing)

'convert stream to byte array...

Dim length As Integer = stream.Length

Dim bytes() As Byte = stream.GetBuffer()

'store in DB

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I managed to reproduce the problem on my side and created new issue #7124 in our defect database. We will investigate the problem and provide you more information.

Best regards.

Any news on this issue?

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. It seems that problem does not occur with the latest version of Aspose.Words. Could you please try using the latest version, you can download it from here:

http://www.aspose.com/community/files/51/file-format-components/aspose.words-for-.net-and-java/entry166389.aspx

Please let me know if problem is resolved.

Best regards.

Hi,

Sorry for not replying earlier. Aspose.Words is not at fault.

GetBuffer returns not real stream bytes but array allocated for these bytes. So it always returns 1024x (seems allocation chunk size). ToArray method should be used instead of GetBuffer.

1 Like

just replace GetBuffer() to ToArray