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

Free Support Forum - aspose.com

Error while creating document from Stream

Hi ,

I am getting error while creating document from stream . Please find the code sample I am using :

Stream inputStream = this.fupManualFileUpload.FileContent;
Aspose.Pdf.Generator.Pdf testpdf = new Aspose.Pdf.Generator.Pdf(inputStream);
Document pdfDocument = new Document(testpdf);

Please suggest. I am need to create a docuemnt from the in memory stream which i have obtained earlier.
I am unable to use the overload method
Document.Document(Stream input) ;
Its giving me “Invalid file format” exception
I even tried doing - Document pdfDocument = new Document(inputStream ); but its failing

Any updates? I am looking for a quick reply . Clients are waiting

Hi Yogesh,

Thanks for contacting support.

Aspose.Pdf.Generator.Pdf object can only be used to create new PDF documents from scratch and I am afraid you cannot load any existing file contents into this object. However if you need to load any existing PDF file, please try using Aspose.Pdf.Document instance. But from your above statement, it appears that you are facing an issue while using Aspose.Pdf.Document object. So can you please share the resource files which you are trying to use while initializing the Document instance, so that we can test the scenario in our environment. We are sorry for this inconvenience.


Please find the resource file which I am using for creating stream attached in this post as well as first post . Yes I am facing issue while using Aspose.Pdf.Document

Following is the error message :
You are in direct-to-file mode,please use Close() instead of Save().
At times i am also getting invalid pdf file format exception . please guide

My intension is to fetch the stream from the upload control using ( Aspose.Pdf.Facades.PdfExtractor) , and then do the barcode validation on the stream , and also do other validations (PDF standard/A )/ transparency / embedded fonts by creating the Aspose.Pdf.Document from the created stream

I am able to do the barcode validation on the stream , but unable to use the same stream to create the Aspose.Pdf.Document
I need to handle it in memory stream

My simple question is , how can i use the overloaded method
Document.Document(Stream input)


Any updates? Please let me know

Hi Yogesh,

Thanks for sharing the details. Please check following code for loading/saving PDF from/to stream using Aspose.Pdf.Document object. Hopefully it will help you to accomplish the task. However if still there is any confusion then please share your sample code here, we will look into it and will guide you accordingly.

byte[] buffer = File.ReadAllBytes(“HelloWorld.pdf”);<o:p></o:p>

MemoryStream inputStream = new MemoryStream(buffer);

// load PDF document

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(inputStream);

MemoryStream outputStream = new MemoryStream();


//convert MemoryStream back to byte array

byte[] data = outputStream.ToArray();

//create a FileStream to save the output PDF file

FileStream output = new FileStream("HelloWorld_out.pdf", FileMode.Create,


//write byte array contents in the output file stream

output.Write(data, 0, data.Length);

//close output file


We are sorry for the inconvenience caused.

Best Regards,