JSPM

  • Created
  • Published
  • Downloads 9127
  • Score
    100M100P100Q130067F
  • License MIT

A utility to print PDF files from Node.js and Electron

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

Build Status codecov npm

A utility to print PDF files from Node.js and Electron.

  • Works on Windows and Unix-like operating systems. If you are looking for a solution for Unix-like operating systems, take a look at the unix-print.
  • Supports label printers such as Rollo and Zebra.

If you rely on this package, please consider supporting it:

Buy Me A Coffee

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 ptp from "pdf-to-printer";

ptp.print("assets/pdf-sample.pdf").then(console.log);

API

.print(pdf[, options]) => Promise<void>

Arguments

  1. 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.
  2. 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]): And since we use SumatraPDF to print documents on Windows you can pass any available in this list option.

Returns

Promise<void>: A promise that resolves undefined.

Examples

To print a PDF file to the default printer:

ptp.print("assets/pdf-sample.pdf").then(console.log);

To print to a specific printer, add the device id of the printer to options:

const options = {
  printer: "Zebra",
};

ptp.print("assets/pdf-sample.pdf", options).then(console.log);

To scale the PDF to fit into the printable area of the paper on both Windows and Unix operating systems:

const options = {
  printer: "Zebra",
  unix: ["-o fit-to-page"],
  win32: ['-print-settings "fit"'],
};

ptp.print("assets/pdf-sample.pdf", options).then(console.log);

.getPrinters() => Promise<Printer[]>

Returns

Promise<Printer[]>: List of available printers.

Examples

ptp.getPrinters().then(console.log);

.getDefaultPrinter() => Promise<Printer> | false

Returns

Promise<Printer | false>: Default printer or false if there is no default printer.

Examples

ptp.getDefaultPrinter().then(console.log);

Contact

Please do not hesitate to report a bug or suggest an idea. You can do it here.

If you are a company and rely on this package, please consider supporting it:

Buy Me A Coffee

License

MIT