I'm trying to render a pdf file created with IronPDF in an iframe, but it only shows a blank file. But if I save the file to the server drive, it works like a charm.
Could it be an encoding problem? This is my code:
$.ajax({
url: $("#host").val() + 'api/Utils/PrintFile',
method: "POST",
responseType: "arraybuffer"
}).then(function (response) {
var file = new Blob([response], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
$("#iPDF").attr('src', fileURL);
$("#iPDF").height("500px");
});
[HttpPost]
[Route("PrintFile")]
public FileStreamResult PrintFile()
{
var Renderer = new IronPdf.HtmlToPdf();
var print = Renderer.RenderUrlAsPdf("http://MyTestUrl/");
//print.SaveAs("C:\\Test\\MyFile.pdf"); <-- This works fine!
var objPrint = print.Stream;
HttpContext.Response.Headers.Add("Content-Type", "application/pdf");
HttpContext.Response.Headers.Add("Content-Disposition", String.Format("{0}; filename=Print.pdf; size={1}", "attachment", objPrint.Length.ToString()));
return File(objPrint, "application/pdf;");
}
Thanks in advance!