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

Free Support Forum - aspose.com

No result trying to save pdf bytes as a new pdf file

Hi, can you please tell me what is wrong with this code. Overall, I am trying to create a pdf object…add pages from various pdf sources and then stream that to a browser, but…to start I am trying to work with the Aspose.Pdf.Generator.Pdf object and when I test the save, the file is not written and when I inspect the variable retVal, the page count is 0. The code reads in a pdf file, writes it back out as A.pdf, which does work, but when I try to write those file contents to a memory stream and then save the Generator.Pdf object, the page out is 0 and no file is written.






Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(“D:\temp\xxx.pdf”);

System.IO.MemoryStream ms2 = new System.IO.MemoryStream();

pdfDocument.Save(ms2);

pdfDocument.Save(“D:\A.pdf”);





Aspose.Pdf.Generator.Pdf retVal = new Aspose.Pdf.Generator.Pdf(ms2);



retVal.Save(“D:\B.pdf”);

Hi Brad,


Thanks for contacting support.

Please note that Aspose.Pdf.Generator only provides the feature to create PDF document from scratch and it does not offer the capability to load existing PDF documents. Therefore when you are trying to instantiate Aspose.Pdf.Generator.Pdf() instance with ms2 object, the page count appears as 0. In case you need to concatenate pages from existing PDF file, please try using Aspose.Pdf.Document object.

Should you have any further query, please feel free to contact.