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

Free Support Forum - aspose.com

Creating PDF from MemoryStream

I am getting error while trying to creating a new pdf from MemoryStream. Below is the code I am using

So, I am getting the memorystream of the file which is on the database as a blob column. Then I am trying to create a new PDF, writing content from memorystream to it and save it on a physical location.

Public string CreatePdfFromMemoryStream()
string filePath = “C:\tempFile\file1.pdf”;
MemoryStream stream = DS.GetDocFileFromDB();
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(stream );
stream .Close();

return filePath;

I am getting the error where it says use “close” instead of “save”.
Please suggest.

Thank you

Hi Ashish,

Thanks for using our products.

Please note that Aspose.Pdf.Generator supports the feature to create PDF document from scratch while using Aspose.Pdf for .NET API. In case you need to read the contents of existing PDF file from MemoryStream, then I would recommend you to please try using Document class to accomplish your requirement. This class provides the feature to Create as well as manipulate existing PDF files.

In the event of any further query, please feel free to contact.


Public string


string filePath = "C:\tempFile\file1.pdf";

MemoryStream stream = DS.GetDocFileFromDB();

Document doc = new Document(stream);



return filePath;