Saving Pdf to Stream

Hi all,<br><br>I was working with the evaluation licence of Aspose.Pdf. I want to save my dynamically created .doc (which is done by Aspose.Words) document as pdf, but I don't want to physically create a file in the disk. I see Pdf class constructor accepts only a filestream as a parameter. Is there a way to save this .doc file to .pdf with a stream other than filestream class instance?<br><br>Thank you<br>

Hi,

Yes you can easily use a MemoryStream in its place.

Thanks.

        MemoryStream ms = new MemoryStream(byteArray);<br>            Document doc = new Document((Stream)ms);<br>              ...<br>              ...<br>             MemoryStream pdfStream = new MemoryStream();<br>            doc.Save(pdfStream, SaveFormat.AsposePdf);<br>            Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf((FileStream)((Stream)pdfStream));             <br>            pdf.Save("cheque", Aspose.Pdf.SaveType.OpenInBrowser, Page.Response);<br>//This causes a build error naturally, because the Pdf class

constructor accepts only FileStream and a memory stream cannot be cast
to a FileStream object.
I cannot begin working with a file stream because I shouldn’t create a file. What should I do?

Hi,

Please try this:

.....
MemoryStream pdfStream = new MemoryStream();
doc.Save(pdfStream, SaveFormat.AsposePdf);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(pdfStream,null);
pdf.Save("cheque", Aspose.Pdf.SaveType.OpenInBrowser, Page.Response);

Thanks.

Thank you so much.