2

I have web application that dynamically generates XHTML. The XHTML is then converted to PDF using Flying Saucer. The document is then streamed to the browser and served inline.

Part of the requirement is to automatically print the generated PDF without user intervention and then closing it. I have never come across such a feature before. Can I print the PDF from a web page using JavaScript? considering I don't have a physical file location!!

Any thoughts on how to tackle this issue would be appreciated

Maro
  • 4,065
  • 7
  • 33
  • 34
  • `Can I print the PDF from a web page using JavaScript?` It is not possible. Maximum what js can do is to open a Print Dialog. – Cheery Feb 10 '12 at 01:45
  • Imagine if it *was* possible for a website to print documents without user intervention. What a mess that would be. –  Feb 10 '12 at 01:47
  • How do I open a print dialog using javascript? – Maro Feb 10 '12 at 01:48
  • `How do I open a print dialog using javascript?` just by `window.print()` – Cheery Feb 10 '12 at 01:49
  • that just calls the print dialog for the browser and not the PDF reader. Which mean I will be restricted by the browser printer settings. which is not desirable – Maro Feb 10 '12 at 01:56
  • Users are in general very glad that they don't get a thousand printed pages for free mortgages or enhanced members every time they open their browser... – sarnold Feb 10 '12 at 01:57
  • 1
    Imagine NOT being restricted by the browser printer settings! I guess HP would throw a donation your way, if you could pull this off ... – Eugen Rieck Feb 10 '12 at 01:58
  • 1
    [Fellow stacker Andrew Thompson](http://stackoverflow.com/a/8446053/377270) has prepared some [JNLP Java Applet examples](http://pscode.org/jws/api.html#prs) showing how to do something similar. I believe they could be employed to do something similar to what you want. – sarnold Feb 10 '12 at 02:01
  • Ok can we lay of the sarcasm for a while. The problem in hand is how to invoke the PDF print functionality automatically. There are already ActiveX controls that can invoke the PDF reader printer dialog bypassing the browser printer setting. http://bytes.com/topic/javascript/answers/870712-print-pdf-file-using-javascript-without-opening (How about that donation now). But hence I don't have a file location and the file is being streamed i cannot think of a way to do it. furthermore ActiveX is not very desirable. So let's think along those lines. Instead of being smug – Maro Feb 10 '12 at 02:08
  • thanks @sarnold will investigate this option for now – Maro Feb 10 '12 at 02:10
  • The applet option is not going to work in this scenario because of the application work flow. It also might freak out the users – Maro Feb 10 '12 at 02:24
  • 1
    Maro - I had a similar issue recently and got some help from others on how to print the PDF in a browser - http://stackoverflow.com/questions/9638989/create-a-print-only-pdf-with-itext – Zack Macomber Mar 12 '12 at 17:07

0 Answers0