Package Exports
- pdf-to-printer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pdf-to-printer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Node.js PDF printing
A utility to print PDF files from Node.js and Electron.
If you are looking for a utility that will work on Unix-like operating systems, then take a look at https://github.com/artiebits/unix-print.
Installation
Install using yarn
:
yarn add pdf-to-printer
Or npm
:
npm install --save pdf-to-printer
Basic Usage
Print a PDF file to the default printer:
import { print } from "pdf-to-printer";
print("assets/pdf-sample.pdf").then(console.log);
API
.print(pdf[, options]) => Promise<void>
Arguments
pdf
(string
): PDF file to print. Will throw an error if no PDF specified. Note: It must be a path to a PDF existing in the file system. You may take a look at this example if you need to download your PDF file first.options
(Object
[optional]):options.printer
: (string
[optional]): Print to the specified printer. Will print to the default printer if device id not specified. If the printer device id mistyped or specified printer does not exist, nothing will print.options.win32
: (array
[optional]): Any available option from this list.
Returns
Promise<void>
: A promise that resolves with undefined.
Examples
To print a PDF file to the default printer:
import { print } from "pdf-to-printer";
print("assets/pdf-sample.pdf").then(console.log);
To print to a specific printer, add the device id of the printer to options:
import { print } from "pdf-to-printer";
const options = {
printer: "Zebra",
};
print("assets/pdf-sample.pdf", options).then(console.log);
To scale the PDF to fit into the printable area of the paper:
import { print } from "pdf-to-printer";
const options = {
printer: "Zebra",
win32: ['-print-settings "fit"'],
};
print("assets/pdf-sample.pdf", options).then(console.log);
.getPrinters() => Promise<Printer[]>
Returns
Promise<Printer[]>
: List of available printers.
Examples
import { getPrinters } from "pdf-to-printer";
getPrinters().then(console.log);
.getDefaultPrinter() => Promise<Printer | null>
Returns
Promise<Printer | null>
: Default printer or null
if there is no default printer.
Examples
import { getDefaultPrinter } from "pdf-to-printer";
getDefaultPrinter().then(console.log);
Sponsor this project
If you rely on this package, please consider supporting it: