2

I am working on a web application developed in Java with struts running on Tomcat. I have a requirement in the web application as follows:

One JSP page having a list of PDF files each associated with a checkbox. The JSP page has one Button. Once the user selects the PDF documents he wants to print by selecting the associated checkboxes, user clicks on the button.

Then all the selected PDF docs should be sent to a specific local Printer( i.e. printer connected to the client machine where from user is accessing the web application). The selected PDF files should not be opened either in acrobat reader or in browser. The PDF docs should not be visible to the user while being sent to printer.

Could anyone please help me in implementing this requirement?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Sangita Pal
  • 21
  • 1
  • 2
  • *"The selected PDF files should not be opened either in acrobat reader or in browser."* Why impose such arbitrary restrictions on the user? Why kill trees? What if the user has no printer? – Andrew Thompson Sep 02 '11 at 12:35

3 Answers3

2

It is possible with Internet Explorer and ActiveX. Search about "auto print" and "silent printing" with Google. You may have to lower security settings in Internet Explorer for that.

We're using it here for some Intranets from our Customers.

For Firefox you may be able to trigger the print dialog via javascript. (http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf) If this is the case you can disable print dialog in FF with setting print.always_print_silent=true in about:config.

Never did it on my own, so I cannot say for sure if it works like the ActiveX thing does.

For Chrome there is an issue requesting same feature like FF has. See https://code.google.com/p/chromium/issues/detail?id=31395.

Fabian Barney
  • 14,219
  • 5
  • 40
  • 60
0

You will most likely have to use a Java Applet for this. The browser have no inherent capability to print a pdf document. You may be able to access the "standard" adobe plugin, but to my knowledge it is not exposed to the standard scripting environment.

You can look here: Can a Java Applet use the printer?

Note: it is recommended to have the applet signed to prevent security restrictions and/or annoying questions to the user to allow access to printer.

You'll also need some form of PDF renderer in your applet (to render to printer). Something like http://java.net/projects/pdf-renderer/, read more here: http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/

Community
  • 1
  • 1
pap
  • 27,064
  • 6
  • 41
  • 46
  • The 'javax.jnlp.PrintService` can print from a sand-boxed applet. See the [PrintService demo.](http://pscode.org/jws/api.html#prs) for an example. – Andrew Thompson Sep 02 '11 at 12:33
0

That is not possible with JavaScript. It is possible with either Flash or a Java applet. In either case, you will need to be able to use both the Printer drivers and a custom PDF reading toolkit. There are adequate plugins for both for PDF reading, and both come with a printing API.

If I may say so, this is a bad requirement -- it is not good to force a user to print a document without reading it -- and should be re-negotiated, especially since it is trivially simple to have those documents print to PDF anyway.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166