when I use pdf1.Save(“C:\Users\Downloads\Report.pdf”);…the pdf file contains all the data…Working fine
Hi Som,
Thanks for your inquiry. Please check the following code snippet to download the PDF file. You need to pass bytes to a response object instead of a file. Hopefully it will help you to accomplish the task.
System.IO.MemoryStream finalStream = new System.IO.MemoryStream();
string documentTitle = "testPDF";
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document("E:/data/helloworld.pdf");
pdf.Save(finalStream);
//To download
byte[] downloadBytes = finalStream.ToArray();
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + documentTitle + ".pdf");
HttpContext.Current.Response.BinaryWrite(downloadBytes);
HttpContext.Current.Response.End();
Please feel free to contact us for any further assistance.
Best Regards,
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(“E:/data/helloworld.pdf”);
Hi Som,
Thanks for your inquiry. Please note download path is not hard coded. We have saved PDF to Stream and passed to response object and browser will download the PDF to default download location of system.
Moreover, Document() constructor and Save() method both has overload with stream/file parameters. You may use any of them as per your requirements.
System.IO.MemoryStream finalStream = new System.IO.MemoryStream();
string documentTitle = "testPDF";
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document("E:/data/helloworld.pdf");
pdf.Save(finalStream);
....
....
Please feel free to contact us for any further assistance.
Best Regards,