I am trying to create a method that sends a PDF file directly to my printer (as a result, a print dialog will appear).
Below is the code I was working on - most of it was found on the forums here . It works fine if I use iTextSharp to create a new PDF document, but as soon as I try to insert some JavaScript into an existing file, I get an exception when calling the print() method saying
The object does not support the property or method 'print'
<script type="text/javascript"> function load() { try { var x = document.getElementById("frame1"); x.print(); } catch (err) { } } </script> <body onload="load();"> <form id="form1" runat="server"> <div> <iframe id="frame1" src="C:/1686850_1.pdf" runat="server" frameborder="0" style="height: 0px; width: 0px;" /> </div> </form> </body> </html>
.CS file
using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; public partial class Print : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SetPDF(File.ReadAllBytes("C:\\1686850.pdf"), "C:\\1686850_1.pdf");
foamy source share