Node.js native module for printer management and printing functionality.
npm install @alexssmusica/node-printer
- Node.js >= 18.0.0
- Windows: No additional requirements
- Linux/macOS: CUPS (Common Unix Printing System)
- Direct printing of raw data or text
- File printing
- Printer management (list, get info, set defaults)
- Job management (view, control)
- Cross-platform support (Windows, Linux, macOS)
Returns an array of all available printers with their properties and current jobs.
const printer = require('@alexssmusica/node-printer');
const printers = printer.getPrinters();
Returns the name of the default printer. Returns null
if no default printer is set.
const defaultPrinter = printer.getDefaultPrinterName();
Get detailed information about a specific printer.
printerName
{String} Name of the printer
const printerInfo = printer.getPrinter('My Printer');
Get printer driver specific options.
printerName
{String} Name of the printer
const driverOptions = printer.getPrinterDriverOptions('My Printer');
Print raw data directly to the printer.
Options:
data
{String|Buffer} Raw data to printprinter
{String} Printer namedocname
{String} Document nametype
{String} Data type (e.g., 'RAW', 'TEXT')
printer.printDirect({
data: 'Hello World!',
printer: 'My Printer',
docname: 'Test Document',
type: 'RAW'
});
Print a file directly to the printer.
Options:
filename
{String} Path to the file to printprinter
{String} Printer namedocname
{String} Document name
printer.printFile({
filename: '/path/to/file.txt',
printer: 'My Printer',
docname: 'File Document'
});
Get information about a specific print job.
printerName
{String} Name of the printerjobId
{Number} ID of the job
const jobInfo = printer.getJob('My Printer', 123);
Control print jobs using various commands.
printerName
{String} Name of the printerjobId
{Number} ID of the jobcommand
{String} Job command
Available commands:
"CANCEL"
"PAUSE"
"RESTART"
"RESUME"
"DELETE"
"SENT-TO-PRINTER"
"LAST-PAGE-EJECTED"
"RETAIN"
"RELEASE"
printer.setJob('My Printer', 123, 'PAUSE');
Get a list of supported print formats for direct printing.
const formats = printer.getSupportedPrintFormats();
Get a list of supported job commands.
const commands = printer.getSupportedJobCommands();
- Supports both local and network printers
- Raw printing supported through Windows API
- Requires CUPS installation
- Minimum CUPS version: 1.1.21 (OS X 10.4)
- Uses CUPS API for printer management and printing
MIT
Contributions are welcome! Please feel free to submit a Pull Request.