Hi. I cant seem to find a working example on how to stream a generated pdf to the browser. When I save the pdf to the file system, it works.
Hi Jonas,
Thanks for your inquiry. Please check the following code snippet to send a PDF document to the browser. Hopefully, it will serve the purpose.
byte[] pdfBytes = File.ReadAllBytes("input.pdf");
Response.Clear();
// Specify the document type.
Response.ContentType = "application/pdf";
// Specify how the document is sent to the browser.
Response.AddHeader("content-disposition", "attachment; filename=test.pdf");
// Another option could be:
// Response.AddHeader("content-disposition", "inline; filename=test.pdf");
// Get data bytes from the stream and send it to the response.
Response.BinaryWrite(pdfBytes);
Response.End();
Please feel free to contact us for any further assistance.
Best Regards,
Hi there.
Hi Jonas,
Yes you are correct. In order to render the PDF document in client browser, you can use an overload of Pdf.Save(…) method which takes HttpResponse object as an argument. Furthermore, you may also take a look over Aspose.Pdf for .NET examples which explain the step on how to render the output to client browser (something similar to Tilal’s comments).