Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Silent print a PDF on client default printer (Newbie)

Status
Not open for further replies.

Drax10

Technical User
Feb 7, 2007
2
US
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();
}
 
if you mean print the document without the user having to explicitly print, you can't. This is a security feature of the browser. You may be able to override this behavior with a customer ActiveX control.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top