Hello,
I'm new to ASP.NET and need to print a PDF file to a client default printer - silently. I'd rather not depend on Acrobat Reader if possible, (even though I used it below). With the following code, I'm able to load the pdf into a web page:
Default.aspx
<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
<script Language='JavaScript' src='js.js'>
Button1_onclick()
</script>
</head>
<body>
<form id="form1" runat="server">
<iframe id="pdfFrame" scrolling="no" runat="server" src="PDFDocument.aspx" style="width:20px; height:30px; border: 0px">
</iframe>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
</form>
</body>
</html>
Default.aspx.cs
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
ClientScript.RegisterStartupScript(typeof(string), "js", "pdf.Print()", true);
}
PDFDocument.aspx
<form id="form1" runat="server">
<object id="pdf" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" viewastext>
<param name="src" value="pdf.pdf">
</object>
</form>
js.js
function Button1_onclick()
{
frames["pdfFrame"].document.pdf.Print();
}
I'm new to ASP.NET and need to print a PDF file to a client default printer - silently. I'd rather not depend on Acrobat Reader if possible, (even though I used it below). With the following code, I'm able to load the pdf into a web page:
Default.aspx
<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
<script Language='JavaScript' src='js.js'>
Button1_onclick()
</script>
</head>
<body>
<form id="form1" runat="server">
<iframe id="pdfFrame" scrolling="no" runat="server" src="PDFDocument.aspx" style="width:20px; height:30px; border: 0px">
</iframe>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
</form>
</body>
</html>
Default.aspx.cs
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
ClientScript.RegisterStartupScript(typeof(string), "js", "pdf.Print()", true);
}
PDFDocument.aspx
<form id="form1" runat="server">
<object id="pdf" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" viewastext>
<param name="src" value="pdf.pdf">
</object>
</form>
js.js
function Button1_onclick()
{
frames["pdfFrame"].document.pdf.Print();
}