views:

1369

answers:

3

In a Web application, is it possible to force a PDF file to be printed on the client? If the browser is configured to open the PDF inside the window, I guess that calling window.print() will work, but some browsers (like mine) are configured to open the PDF externally.

+6  A: 

The way google docs does it is by embedding JavaScript into the PDF that tells Acrobat Reader or any other compliant reader to print it.

You would need a PDF toolkit to do this with a random PDF.

Lou Franco
You don't need PDF toolkit if you can use iTextSharp. Here is a link to a page tells you how to add javascript to the PDF using iTextSharp that will print the pdf. http://itextsharp.sourceforge.net/tutorial/ch11.html
Dave
iTextSharp is a PDF toolkit.
Lou Franco
+2  A: 

Do you mean that you want to force the file to be sent to a printer? Are you thinking of the Law of Unintended Consequences -- the user's device isn't connected to a printer? Could be a BlackBerry, could be a laptop on wi-fi. What if the user doesn't want it to go to the default printer?

DOK
My only printer at home is PDFCreator.
Kibbee
Spot on. Whenever I ask this kind of question then go ahead and implement it, it turns out I really should have wished for someone to point out what DOK pointed out.
Mihai Limbășan
Yeah, but then your boss, who knows that only ten employees at his office will ever use this web page, and knows they have printers, will be baffled by the fact that you can make a computer do almost anything, but you cannot make it open a print dialog.
PeterAllenWebb
+1  A: 

you can set a http header to application/pdf and then force a new window open with javascript and print that way. but who would really do that? i mean come on now.