This is a printing service class serving following functions
- Discover IPP Printers in the local network
- Get Printer via IPP Protocols
- Get Printer's Supported Job Attributes
- Send and Print JPEG
- Check Print Job (with Job ID)
npm install --save c15yo-printing
// Using require()
const Printer = require('c15yo-printing')
Create an instance of the Printer
class.
// ES2015 modules
const Printer = require('c15yo-printing')
const printer = new Printer();
By initializing an instance of Printer
, a mDNS discovery service will start searching and detects updates from the network.
Since printer discovery service is started since Printer
instance is created. This feature queries the list of printer and returns necessary information.
{
// Printer
"10.0.0.254": {
"status": "OK", // Printer query status, "OK" or "ERROR"
"mdns": [MDNS Object], // mDNS query result in Object format
"printer": [IPPPrinter Object], // If status is "OK", this object will be populated. Printer full attributes information in Object format
"error": [Error] // If status is "ERROR", this object will be populated.
},
... // More printers
}
mDNS Object from local network discovery
{
"addresses": [Array(String)], // Array of address
"query": [Array(String)], // Array of MDNS queries
"type": [Array(Object)], // Array of MDNS responses and supported protocols
... // Unnecessary items
}
IPP Printer Object
{
"version": "2.0", // IPP Protocol Version
"statusCode": "successful-ok", // IPP Query status
"id": 24255051, // IPP Query ID
"operation-attributes-tag": [Object], // Printer operational configuration tags
"printer-attributes-tag": [Object], // Printer operational attributes
}
var printers = printer.getPrinters()
Type: string
IP Address of the printer. This ip address must be from discovered printer list or null will be returned.
{
"status": "OK", // Printer query status, "OK" or "ERROR"
"mdns": [MDNS Object], // mDNS query result in Object format
"printer": [IPPPrinter Object], // If status is "OK", this object will be populated. Printer full attributes information in Object format
"error": [Error] // If status is "ERROR", this object will be populated.
}
Type: string
IP Address of the printer.
Type: function(error, result)
Arguments:
error
: If no error occured, this object will be undefined
. Otherwise, an Error
object will be returned.
result
: If no error occured, this object will be populated with an IPP Printer Object
Send a JPEG print job to the printer
Type: string
IP Address of the printer.
Type: JavaScript Buffer <buffer>
| String
JPEG Buffer. e.g. fs.readFileSync('something.jpg')
Type: Object
{
"job-attributes-tag": [Object], // Print job attributes. e.g. Copies, Quality, etc.
}
Type: function(error, result)
Arguments:
error
: If no error occured, this object will be undefined
. Otherwise, an Error
object will be returned.
result
:
{
"status": "OK", // "OK" or "ERROR"
"data": [Object] | String, // If status is "OK", an IPP Job Object will be populated here.
// If there is an error, this field will be an error message.
"job": String // If status is "OK", a base64 encoded print job uri will be populated here.
}
Get processing
, completed
or cancelled
print job details by the job
id.
Type: string
IP Address of the printer.
Type: string
Job URI. (By decoding the base64 job id. see printJPEG
=>callback
.
Type: function(error, result)
Arguments:
error
: If no error occured, this object will be undefined
. Otherwise, an Error
object will be returned.
result
:
{
"status": "OK", // "OK" or "ERROR"
"job": [Object] // If status is "OK", job object will be populated here.
}