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

Free Support Forum - aspose.com

PDF Error when saving word document to PDF

I’m using a memorystream which is a word document. I’m trying to convert this into a pdf using the latest v 9 dlls. It saves the file successfully (attachment in an email) however when trying to open the document it throws the following error "Adobe Reader could not open the ‘test.pdf’ because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn’t correctly decoded)


Could anyone please help ? I need this code to work before releasing an update to my client.

docContents is a byte[]

MemoryStream tStream = new MemoryStream(docContents);
Aspose.Words.Document tDoc = new Aspose.Words.Document(tStream); tDoc.SaveToPdf(0, tDoc.PageCount, docStream, null);
tStream.Dispose();

I tried to use pdfComplaince.PdfA1b but that didnt work either.

Vinny

Hi

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

Thanks for your request. Could you please attach your input document and output PDF? I will check the issue and provide you more information.

Also, it would be great if you create a simple application, which will allow me to reproduce the problem on my side.

Best regards.

I turned the .docx into a byte array which are then loaded into a memorystream as per the original post.


enclosed you would find the docx and the output pdf which is broken.

thanks

vincent

Hello

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

Thank you for additional information. I cannot reproduce the problem on my side using the latest version of Aspose.Words (9.1.0). You can download this version from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

I use the following code for testing:

//Read DOC form file.

byte[] docBytes = File.ReadAllBytes("Implement+traffic+lights+on+tasks.docx");

//Create MemoryStream from byte array

MemoryStream docStream = new MemoryStream(docBytes);

Document doc = new Document(docStream);

doc.SaveToPdf("out.pdf");

Best regards,

It needs to be output to a memory stream for attachment to an email.

eg.
byte[] docBytes = File.ReadAllBytes(“Implement+traffic+lights+on+tasks.docx”);
MemoryStream tStream = new MemoryStream(docBytes);
Document tDoc = new Document(tStream);
MemoryStream attachStream = new MemoryStream();
tDoc.SaveToPdf(0,tDoc.PageCount,attachStream,null);
Attachment emailAttachment = new Attachment(attachStream, “doc.pdf”);

– do send mail

When opening attachment it give the error

Hello

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

Thank you for additional information. You should just add the following line of code:

byte[] docBytes = File.ReadAllBytes("Implement+traffic+lights+on+tasks.docx");

MemoryStream tStream = new MemoryStream(docBytes);

Document tDoc = new Document(tStream);

MemoryStream attachStream = new MemoryStream();

tDoc.SaveToPdf(0, tDoc.PageCount, attachStream, null);

attachStream.Seek(0, SeekOrigin.Begin);

Attachment emailAttachment = new Attachment(attachStream, "doc.pdf");

Best regards,

Thank you SO much.


That last 1 did the trick.

Again thanks for the speedy response

Vinny