Skip to content

yevgenko/printer-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Share standard printers via JSON API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published