Crackermann
Crackermann

Reputation: 65

Printing a page to different printers in a web app

I want to write a web app that can process a users presentation which when submitted, gets sent to their local system printers - one part of the order will go to B&W laser printer and another part goes to another printer for another process.

Ideally, this will be able to run on any of the major systems - Linux, OSX or Windows.

It could be a packaged Chrome or Firefox app or extension, but I can't tell if there is sufficient access to the system printers. (I can see all the printers available to my current chrome installation - but are they available to an extension?). I can't see the code in any demos or libraries.

I've seen reference to NPAPI, but I can't tell if that's what I need either - if so would I need to write an app for each of the major platforms or each kind of printer?

Upvotes: 2

Views: 4613

Answers (1)

nmaier
nmaier

Reputation: 33162

In Firefox it is possible to print from an extension. Using only javascript, that is (you're free to mess about with C++ if you like). Extensions are essentially the browser: Everything the browser can do, an extension can, too.

There is however not much documentation about using the printer. To be precise, there is none that I'm aware of. However, the browser is open source, and the UI is mostly Javascript, so you can just read the code.

printUtils.js would be a good starting point to check out how this might work. Also there is a component implementing nsIPrinterEnumerator. See the info section for a collection of "Getting started" and documentation resources about add-on development in general.

I don't think the Chrome extension API provides ways to control printing the way you'd need.

The NPAPI plugin API does not provide enough control over printing. You just basically get a buffer to draw into, but no way to control printing setting or initiate printing yourself. You could cheat of course, and have your plugin directly print something via OS bypassing the browser, like e.g. those PDF readers do. However, it should be noted that NPAPI plugins are the past... Don't develop new ones, if possible.

Upvotes: 3

Related Questions