I'm trying to add a feature to download a pdf file. I'm using ironpdf to generate the pdf file and I want the user to click and download it.
Here is my handler.
try
{
// Render any HTML fragment or document to HTML
var Renderer = new IronPdf.HtmlToPdf();
var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
var data = PDF.MetaData;
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.Buffer = true;
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("content-disposition", "attachment;filename=Cotacao.pdf");
context.Response.BinaryWrite(PDF.BinaryData);
context.Response.Flush();
}
catch (Exception e)
{
}
finally
{
context.ApplicationInstance.CompleteRequest();
}
Here is my ajax request
function GeneratePDF() {
return $.ajax({
type: "POST",
url: "../Handlers/GeneratePDF.ashx",
success: PDFSuccess,
error: PDFError
});
I can see the output stream response in the browser but no download dialog. What am I doing wrong?
Thanks in advance.