Skip to content
Share standard printers via JSON API
JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json
standalone.js

README.md

Printer Express

Share standard printers via JSON API

Build Status

Usage

Standalone

Clone repository:

git clone git@github.com:yevgenko/printer-express.git

Install dependencies:

cd printer-express
npm i

Run the server (default port is 3000, but can be adjusted via environment variable PORT):

node standalone.js

ExpressJS Middleware

Install printer-express package with npm:

npm i printer-express --save

Use middleware with Express application:

var express = require('express'),
    printerExpress = require('printer-express'),
    app = express(),
    port = process.env.PORT || 3000;

// mount point for JSON API, i.e. /cloudprint/printers and /cloudprint/jobs
app.use('/cloudprint', printerExpress);
app.listen(port);

JSON API

GET /printers

Get the list of printers installed on the hosting system:

curl -v http://localhost:3000/printers

or with jQuery:

$.getJSON("http://localhost:3000/printers");

POST /jobs

Submit new printing job:

curl -v -X POST http://localhost:3000/jobs -H "Content-Type: application/json" -d '{"data":"Hello, World!", "type":"RAW", "printer":"stkPrinter"}'

or with jQuery:

$.ajax({
  type: 'POST',
  url: "http://localhost:3000/jobs",
  data: JSON.stringify({data: 'Hello, World!', type: 'RAW', printer: 'stkPrinter'}),
  dataType: 'json',
  contentType: "application/json; charset=utf-8"
});

To print from file, i.e. PDF, simply replace data and type attributes with url pointing to the publicly accessible file, for example:

curl -v -X POST http://localhost:3000/jobs -H "Content-Type: application/json" -d '{"url":"http://example.com/print.pdf", "printer":"stkPrinter"}'

We can also omit the printer attribute, in which case system default printer will be used.

You can’t perform that action at this time.