Pdf file not loaded properly In Aspose

when I use pdf1.Save(“C:\Users\Downloads\Report.pdf”);…the pdf file contains all the data…Working fine


but I don’t want to hardcoded the path…I just want to save it in client’s machine…means using HttpContext.Current.Response…

like below code…(What we do asusual In Itextsharp…)

Document pdfDocument = new Document(PageSize.B0, 10f, 10f, 10f, 10f);
HttpContext.Current.Response.ContentType = “application/pdf”;
HttpContext.Current.Response.AppendHeader(“contentdisposition”,“attachment;filename=Utilization Report.pdf”);
HttpContext.Current.Response.Write(pdfDocument);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

So in Aspose what we have to do to get this type of result…





Hi Som,


Thanks for your inquiry. Please check following code snippet to download the PDF file. You need to pass bytes to response object instead file. Hopefully it will help you to accomplish the task.

System.IO.MemoryStream finalStream = new System.IO.MemoryStream();<o:p></o:p>

string documentTitle = “testPDF”;<o:p></o:p>

Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(“E:/data/helloworld.pdf”);<o:p></o:p>

pdf.Save(finalStream);<o:p></o:p>

byte[] downloadBytes = finalStream.ToArray();<o:p></o:p>

HttpContext.Current.Response.AddHeader(“Content-Type”, “application/pdf”);<o:p></o:p>

//To download<o:p></o:p>

HttpContext.Current.Response.AddHeader(“Content-Disposition”, “attachment; filename=” + documentTitle + “.pdf”);<o:p></o:p>

HttpContext.Current.Response.BinaryWrite(downloadBytes);<o:p></o:p>

HttpContext.Current.Response.End();<o:p></o:p>

<o:p> </o:p>

<o:p>
</o:p>

<o:p>Please feel free to contact us for any further assistance.</o:p>

<o:p>
</o:p>

Best Regards,

Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(“E:/data/helloworld.pdf”);


I dont want to hardcode the path because how can i know what is the default download path in client’s machine…

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();<o:p></o:p>

string documentTitle = “testPDF”;<o:p></o:p>

Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(“E:/data/helloworld.pdf”);<o:p></o:p>

pdf.Save(finalStream);


Please feel free to contact us for any further assistance.


Best Regards,