Click here to Skip to main content
14,430,298 members

Send PDF files directly to client printer without dialog box in ASP.NET application

Rate this:
3.24 (12 votes)
Please Sign up or sign in to vote.
3.24 (12 votes)
28 Nov 2013CPOL
How to send PDF files directly to client printer without dialog box in ASP.NET application


This tip will show you how to send PDF files to a client printer without a dialog box in an ASP.NET application.


A few days ago, one of our clients demanded that PDF reports generating from our web application should be sent to his printer directly without asking him to download those PDFs. So after two days of searching, I found a breakthrough solution here. But, in this solution, there is a select printer dialog box asking the user to press "OK" (but our client did not even want to click that single "OK") button, so I modified that solution to suppress the printer selection dialog box, and now when the user presses the "Save and print" button in our application, the system saves the data into the database, generates a report file (PDF) on the hard disk, and then sends that PDF to the client's default printer without any further click.

Using the Code

So here is the trick. Place the following object tab in your .aspx file:

<object id = "Object1" name="Pdf2" 

type="application/pdf" WIDTH="1" HEIGHT="1" >
            <PARAM NAME='SRC' VALUE='<%= SReportFileName %>'>

Here, SReportFileName is a static variable on my .cs file in which I will set my PDF file name (because PDF files are generated at run time, they have temporary names).

If you have a static PDF file, then you can write that name directly like this:

<object id = "Object1" name="Pdf2" 

type="application/pdf" WIDTH="1" HEIGHT="1" >
            <PARAM NAME='SRC' VALUE='myfile.pdf'>

Now in your CS file, after creating and saving your PDF file on the server, you can set the SReportFileName variable and call the <object> printAll() method to do printing on the printer.

public static string SReportFileName = ""; 

SReportFileName = "your file path and name" // temp/mypdf.pdf 

ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", 
"<script language='JavaScript'>document.Pdf2.printAll()</script>");  

Note that the client must have Acrobat Reader installed on his machine for this solution to work.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

kashif Atiq
Software Developer (Senior) Spctek
Pakistan Pakistan
No Biography provided

Comments and Discussions

QuestionProblem with Printers in other network. Pin
R_042910-Apr-17 21:13
MemberR_042910-Apr-17 21:13 
GeneralMy vote of 1 Pin
Sharma Richa19-Jul-14 12:36
MemberSharma Richa19-Jul-14 12:36 
BugNot working Pin
Raj_Doshi272-Dec-13 18:54
professionalRaj_Doshi272-Dec-13 18:54 
GeneralMy vote of 1 Pin
athg2-Dec-13 0:44
Memberathg2-Dec-13 0:44 
GeneralMy vote of 2 Pin
Chris1983.NET1-Dec-13 23:51
MemberChris1983.NET1-Dec-13 23:51 
QuestionThis is not not work for me Pin
Sadequzzaman Monoj1-Dec-13 18:27
professionalSadequzzaman Monoj1-Dec-13 18:27 
SuggestionSome Alternative and more "involved" options... Pin
MacSpudster29-Nov-13 9:08
professionalMacSpudster29-Nov-13 9:08 
GeneralRe: Some Alternative and more "involved" options... Pin
VMAtm3-Dec-13 3:53
MemberVMAtm3-Dec-13 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 28 Nov 2013


15 bookmarked