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

Free Support Forum - aspose.com

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>


Yes you can easily use a MemoryStream in its place.


        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?


Please try this:

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


Thank you so much.