• Stars
    star
    412
  • Rank 105,024 (Top 3 %)
  • Language
    JavaScript
  • Created almost 12 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Internet Printing Protocol (IPP) for nodejs

Internet Printing Protocol (IPP) for nodejs


A pure Javascript implementation of the IPP/2.0 protocol that has no dependencies.

The IPP protocol was started in the 90's and is still being worked on today. It is a very indepth protocol that spans many RFCs- some of which are dead while others were herded into IPP/v2.x.

There are millions of printers that support IPP. If you have one, this module will allow you to send/recieve data to/from the printer.

To find out if your printer supports IPP:

  • Google your printer's specs
  • Try: telnet YOUR_PRINTER 631. If it connects, that's a good sign.
  • Use the '/examples/findPrinters.js' script.

I have a pretty good starting point here. I created reference files (attributes, enums, keywords, operations, status-codes, versions and tags) and tried to include as many links in the comments to the ref docs as I could.

Install

$ npm install ipp

Printer(url [,options])

var ipp = require('ipp');
var PDFDocument = require('pdfkit');

//make a PDF document
var doc = new PDFDocument({margin:0});
doc.text(".", 0, 780);

doc.output(function(pdf){
	var printer = ipp.Printer("http://NPI977E4E.local.:631/ipp/printer");
	var msg = {
		"operation-attributes-tag": {
			"requesting-user-name": "William",
			"job-name": "My Test Job",
			"document-format": "application/pdf"
		},
		data: pdf
	};
	printer.execute("Print-Job", msg, function(err, res){
		console.log(res);
	});
});

To interact with a printer, create a Printer object.

Technically speaking: a Printer object does not need to be an actual printer. According to the IPP spec, it could be any endpoint that accepts IPP messages. For example; the IPP object could be persistant media- like a CD ROM, hard drive, thumb drive, ...etc.

options:

  • charset - Specifies the value for the 'attributes-charset' attribute of requests. Defaults to utf-8.
  • language - Specifies the value for the 'attributes-natural-language' attribute of requests. Defaults to en-us.
  • uri - Specifies the value for the 'printer-uri' attribute of requests. Defaults to ipp://+url.host+url.path.
  • version - Specifies the value for the 'version' attribute of requests. Defaults to 2.0.

printer.execute(operation, message, callback)

Executes an IPP operation on the Printer object.

  • 'operation' - There are many operations defined by IPP. See: /lib/enums.js.
  • 'message - A javascript object to be serealized into an IPP binary message.
  • 'callback(err, response)' - A function to callback with the Printer's response.

ipp.parse(buffer)

Parses a binary IPP message into a javascript object tree.

var ipp = require('ipp');
var data = new Buffer(
    '0200' +	//version 2.0
		'000B' +	//Get-Printer-Attributes
		'00000001'+	//reqid
		'01' +		//operation-attributes-tag
		//blah blah the required bloat of this protocol
		'470012617474726962757465732d6368617273657400057574662d3848001b617474726962757465732d6e61747572616c2d6c616e67756167650002656e' +
		'03'		//end-of-attributes-tag
	,'hex');


var result = ipp.parse(data);
console.log(JSON.stringify(result,null,2));
//  ta-da!
//{
//	"version": "2.0",
//	"operation": 11,
//	"id": 1,
//	"operation-attributes-tag": {
//		"attributes-charset": "utf-8",
//		"attributes-natural-language": "en"
//	}
//}

ipp.serialize(msg)

Converts an IPP message object to IPP binary.

See request for example.

ipp.request(url, data, callback)

Makes an IPP request to a url.

var ipp = require('ipp');
var uri = "your_printer";
var data = ipp.serialize({
	"operation":"Get-Printer-Attributes",
	"operation-attributes-tag": {
		"attributes-charset": "utf-8",
		"attributes-natural-language": "en",
		"printer-uri": uri
	}
});

ipp.request(uri, data, function(err, res){
	if(err){
		return console.log(err);
	}
	console.log(JSON.stringify(res,null,2));
})
//  ta-da!.. hopefully you'll see a ton of stuff from your printer

Browser Support?

See this thread

License

MIT

More Repositories

1

mongo-mock

Let's pretend we have a real MongoDB
JavaScript
240
star
2

litesocket

Realtime server events for Node.JS, using Server Sent Events (SSE)
JavaScript
30
star
3

webserial

A browser based serial app
Vue
28
star
4

sqlbits

An assortment of powerful & well tested functions that assist in building SQL statements
JavaScript
16
star
5

irc-replies

RFC 1459 IRC reply codes
14
star
6

nodeirc

Information about the Node.js IRC community
HTML
14
star
7

irc-connect

Minimal IRC connection that simply emits event objects. Plugin modules can do the rest.
JavaScript
14
star
8

scomm

A cross browser window/tab messaging framework.
JavaScript
8
star
9

extensions

Doin' freaky nasty things to the built-in prototypes.
JavaScript
8
star
10

propex

Describe objects with Property Expressions
HTML
8
star
11

node-eachline

Streams2 line reader
JavaScript
6
star
12

orgbot

Keep your GitHub owners to a minimum- use this bot to manage your org instead.
JavaScript
6
star
13

amazon-drive

A Node.js client for Amazon Drive
JavaScript
6
star
14

vl53l0x

A Node.js library for a vl53l0x device
JavaScript
6
star
15

ads1115

A Node.js library for an ads1115 analog to digital converter
JavaScript
5
star
16

allow

define and validate objects using a propex
JavaScript
5
star
17

irc-channels

Add channel features to irc-connect
JavaScript
5
star
18

ssd1327

A Node.js library for an ssd1327 oled display
JavaScript
4
star
19

comm

Decoupled javascript communication library
JavaScript
3
star
20

ezfs

Create/Read/Delete files and directories like they are JavaScript objects!
JavaScript
3
star
21

node-eachfile

Iterate over the files of a directory
JavaScript
3
star
22

bndlr

Static Content Bundler
JavaScript
3
star
23

consumer

Consume Javascipt strings character-by-character.
JavaScript
3
star
24

propex-validation

Uses Propex to validate javascript objects
JavaScript
3
star
25

crap

Ⓒontrollers Ⓡesources Ⓐnd ⓟroviders framework
JavaScript
2
star
26

i2cdriver

A Node.js library for a i2cdriver device http://i2cdriver.com
JavaScript
2
star
27

hook-relay

A server that accepts POSTs from Github Webhooks and relays them to Server Sent Event clients
JavaScript
2
star
28

sixchars

Encode/Decode random looking 6 character strings for a number.
JavaScript
2
star
29

AAAA

Some things I find useful
C#
2
star
30

get-then

Give a URL, Get a Buffer.
JavaScript
2
star
31

ldml

Read CLDR XML data with inheritance
JavaScript
1
star
32

tfmini-plus

A Node.js library for the TFMini Plus
JavaScript
1
star
33

amazon-drive-sync

A Node.js Amazon Drive synchronization service
1
star
34

vl53l1x

A Node.js library for a vl53l1x device
JavaScript
1
star
35

effd

Æ’ them Promise()s!!
JavaScript
1
star
36

bndlr-advanced

An example of using bndlr with more advanced requirements
JavaScript
1
star
37

bndlr-basic

An example of using bndlr with a simplistic website structure.
JavaScript
1
star