I've converted HTML+CSS to a PDF using EO.PDF, and I have it streamed to the browser. Once loaded, I'm trying to get Adobes print dialog to pop up. I've had it working with Aspose.Words for a while, but can't full convert to EO.PDF without this working.
Code I'm trying:
Code: C#
var htmlContent = passedInHtmlVar + "<script type=\"text/javascript\">var pp = getPrintParams(); pp.interactive = pp.constants.interactionLevel.full; print(pp);</script>";
Response.ContentType = "application/pdf";
EO.Pdf.HtmlToPdf.ConvertHtml(htmlContent, Response.OutputStream);
Response.End();
This renders the PDF perfectly, but the print dialog never shows. To see if the javascript was working, I added some JS to modify parts of the document, and the modifications worked great leaving me confused to the problems with the script.
Code for Aspose.Words that works:
Code: C#
var fileName = String.Format("{0}{1}.pdf", AppDomain.CurrentDomain.BaseDirectory, fileName);
using(var htmlStream = new MemoryStream(Encoding.UTF8.GetBytes(html)))
{
var doc = new Document(htmlStream);
doc.Save(outStream, SaveFormat.Pdf);
}
byte[] content;
using(var ms = new MemoryStream())
{
var pdf = new PdfReader(fileName);
var stamper = new PdfStamper(pdf, ms);
var writer = stamper.Writer;
writer.AddJavaScript("var kk = getPrintParams(); kk.interactive = kk.constants.interactionLevel.full; print(kk);");
stamper.Close();
content = ms.ToArray();
}
if (File.Exists(fileName))
{
File.Delete(fileName);
}
Response.ContentType = "application/pdf";
Response.BinaryWrite(content);
Response.End();
I've searched the forums, and documentation; I can't seem to figure out the mistake I'm making here. Hopefully someone can point out the issue, since I would prefer to swap to EO.PDF as it has far superior conversion results as far as I can tell.
Thanks.