Printing from a web app directly to a printer
Three ways to print directly to printers from a web app:
1. Print by email
HP printers support ePrint, which is the ability to email a doc, pdf, html, or jpg to a printer. It will print automatically, without going through a PC. If it's a recent HP printer (~3 years or less old), it will support ePrint. I worked on a Rails app about two years ago where we built this. We asked the user for the printer's email address and stored it. When we had a print ready for them, we used ActionMailer to build an email, attach a PDF, and send it. ActionMailer supports attachments pretty easily: http://guides.rubyonrails.org/action_mailer_basics.html#complete-list-of-action-mailer-methods
Some wikipedia info on HP ePrint: http://en.wikipedia.org/wiki/HP_ePrint
I work for HP, but I just checked, and it looks like Epson also supports (Email Print).
2. Print by Cloudprint
Another choice, especially if you want to check if the printer is online or if the print job completed, is to use Google Cloudprint. I haven't implemented anything with Cloudprint, but it has a RESTful API:https://developers.google.com/cloud-print/docs/appDevGuide. On the user's side, they can use a printer that directly supports Cloudprint. Again, I know HP printers can do this (http://www.google.com/cloudprint/learn/setup-hp.html), but other manufacturers might support it as well. (Indeed, Google shows many that do.)
If the user doesn't have a cloudprint capable printer, all is not lost! Google Chrome can act as a proxy for any legacy printer. Google has a support doc that explains how.
3. Print by local network
If you know the printer is on the local network, such as when you've got a centralized reporting server for a company, then you've got a third option. Assuming your app server is on a Linux box, you can use CUPS to send a job to the printer. Then you can use lpr to send a PDF file to the printer.
More from Will
Here are Will's detailed code tutorials that we have migrated to Print Fundamentals for Developers on the HP Developers' Portal
- Using PDF to make webpages print beautifully
- Generating PDFs from HTML for non-web applications (like book layout)
- Printing with CSS and Media Queries
Will's blog and forum posts
- Selecting regions of a webpage to print
- Printing HTML headers and footers
- Web printing in landscape
- In-browser preview of print CSS