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

Free Support Forum - aspose.com

Converting document to pdf by using streams

Hi ,

I am trying to convert document to PDF by using streams and attaching final stream as mail attachment but pdf is not converting and get incorrect format message while opening the attachment. Please help me.

Aspose.Words.Document doc = new Aspose.Words.Document(@"C:\Documents and Settings\cmylavarapu\My Documents\document.doc");

MemoryStream memStream1 = new MemoryStream();

doc.Save(memStream1, SaveFormat.AsposePdf);

memStream1.Seek(0, SeekOrigin.Begin);

//Load the document into an XmlDocument

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(memStream1);

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

MemoryStream memStream2 = new MemoryStream();

pdf.BindXML(xmlDoc, null);

pdf.Save(memStream2);

Hello Dear,

Thank you for using Aspose products.

I'm looking into the matter and will let you know as I find some resolution.

Regards,

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

Thanks for considering Aspose.

Please close the MemoryStream objects, before using them as attachment. Try appending the following code lines at the end of code snippet that is converting Word file into Pdf.

memStream1.Close();

memStream2.Close();

I have tested the issue and have tried saving the resultatn file to hard-drive and its working properly. Please make sure you are using the latest version of Aspose.Pdf. In case the issue still parsists, please share the resource word file, so that we can test the issue at our end.

Hi,

Please add following line before using the stream as an attachment:

memStream2.Position = 0;

mailmessage.Attachments.Add(new System.Net.Mail.Attachment(memStream2,"test.pdf"));

I'm sure this is gonna solve the problem, and attached pdf will open successfully; which I have already seen at my end.

However, I would recommend not to close the stream before sending the email, because that way SMTP Client won't be able to access the closed stream.

I hope this helps; if you have any more issues please let us know.

Regards,

Thank you shahzad.

Thank you I had the same problem!