Printer : Printer operation
This module provides printer functionality, EdgerOS App can use this module to print files in various formats.
This module is the asynchronous mode of the Printer
module.
var Printer = require('async/printer');
EdgerOS apps needs permission.printer
permission to use the printer. For details, please refer to permission.
Support
The following shows Printer
module APIs available for each permissions.
User Mode | Privilege Mode | |
---|---|---|
Printer | ● | ● |
Printer.list | ● | ● |
printer.name | ● | ● |
printer.print | ● | ● |
printer.state | ● | ● |
printer.capabilities | ● | ● |
Printer Class
new Printer(name)
name
{String} Printer name.- Returns: {Object} Printer object.
Create a printer object, name
must be a printer name that has been added to the system.
async Printer.list()
- Returns: {Array} Array of printer information.
Get the list of printers currently added to the system. Each item of the returned array has the following members:
uri
{String} Printer URI.name
{String} Printer name.model
{String} Printer model, eg:Canon MF230 Series
.state
{String} Printer state. The possible states are shown in the table below:
State | Description |
---|---|
'idle' | Printer is idle. |
'stopped' | Printer is paused. |
'processing' | Printer is working. |
Example
async function create() {
var printers = await Printer.list();
if (printers.length) {
return new Printer(printers[0].name);
}
}
Printer Object
printer.name
- {String} Printer name.
The name
attribute is the same as the parameter when the printer object was created.
async printer.print(output, format, info[, opt])
output
{Buffer | Readable} What needs to be printed.format
{String} Output content format.info
{String} Job information.opt
{Object} Print options.- Returns: {Integer} Job ID.
Submit a print job and the printer will print in the order of the job.
Supported document formats(case insensitive):
TXT
|TEXT
PDF
GIF
BMP
PNG
JPG
|JPEG
TIFF
Print options can contain the following:
color
{String}'color'
or'grayscale'
. default:'color'
.copies
{Integer} Number of copies (1 ~ 10). default: 1.range
{Object} PDF file page range.start
{Integer} Start page number. default: 1.end
{Integer} End page number. default: last page number.
sides
{Integer} Single and double-sided printing. default: 1. single side.media
{String} Page size. for example: ISO A4 paper is'iso_a4_210x297mm'
. default: The printer decides.quality
{String} An enumeration specifying the desired print quality.draft
,normal
, andhigh
quality. default: The printer decides.
opt.sides
values are as follows:
1
: Single page.2
: Two sided long edge.3
: Two sided short edge.
Example
// Submit a print job using stream.Readable
var output = fs.createReadStream('./a.pdf');
var id = await printer.print(output, 'pdf', 'a.pdf');
// Submit a print job using buffer
var chunk = fs.readFile('./b.jpg');
var id = await printer.print(chunk, 'jpg', 'b.pdf');
The media
and quality
option is available in EdgerOS 2.2.2 and above.
async printer.state()
- Returns: {String} Printer state.
Get the state of the specified printer. The possible states are shown in the table below:
State | Description |
---|---|
'idle' | Printer is idle. |
'stopped' | Printer is paused. |
'processing' | Printer is working. |
'offline' | Printer is offline. |
async printer.capabilities()
- Returns: {Object} Printer capabilities.
Get printer capability attributes of the specified printer. The returns object has the following properties:
color
{Boolean} Whether to support color printing.sides
{Integer} Whether to support double-sided printing.1
: one side,2
: two sides.copies
{Integer} Maximum number of print copies supported.range
{Boolean} Whether to support printing range selection.media
{Object} Page size information.support
{StringArray} List of paper sizes supported by the printer.ready
{StringArray} Printer-ready list of paper sizes.
quality
{StringArray} A list of supported print qualities, for exampledraft
,normal
, andhigh
.
This feature is supported in EdgerOS 2.0.6 and above. The media
and quality
option is available in EdgerOS 2.2.2 and above.