https://github.com/artiebits/pdf-to-printer
Print PDFs and images from Node.js and Electron
https://github.com/artiebits/pdf-to-printer
electron jpeg nodejs pdf pdf-printer png printer rollo-printer silent-printing windows zebra-printer
Last synced: about 1 month ago
JSON representation
Print PDFs and images from Node.js and Electron
- Host: GitHub
- URL: https://github.com/artiebits/pdf-to-printer
- Owner: artiebits
- License: mit
- Archived: true
- Created: 2019-07-13T18:20:35.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-15T06:56:10.000Z (about 2 years ago)
- Last Synced: 2024-10-29T03:18:42.401Z (7 months ago)
- Topics: electron, jpeg, nodejs, pdf, pdf-printer, png, printer, rollo-printer, silent-printing, windows, zebra-printer
- Language: TypeScript
- Homepage: https://artiebits.com
- Size: 43.3 MB
- Stars: 432
- Watchers: 8
- Forks: 135
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Node.js printing
[](https://cirrus-ci.com/github/artiebits/pdf-to-printer)
[](https://codecov.io/gh/artiebits/pdf-to-printer)
A utility for printing PDFs and images from Node.js and Electron.
- Available only on Windows. The Unix-like operating systems utility can be found on https://github.com/artiebits/unix-print.
- It supports label printers like Rollo and Zebra.## Support This Project
If you rely on this package, please consider supporting it. Maintaining an open source project takes time and your support would be greatly appreciated.
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [API](#api)
- [`.print(pdf[, options]) => Promise`](#printpdf-options--promisevoid)
- [`.getPrinters() => Promise`](#getprinters--promiseprinter)
- [`.getDefaultPrinter() => Promise`](#getdefaultprinter--promiseprinter--null)
- [License](#license)## Installation
You can install the package using `npm`:
```bash
npm install --save pdf-to-printer
```Or `yarn`
```bash
yarn add pdf-to-printer
```## Basic Usage
To print a file to the default printer:
```javascript
import { print } from "pdf-to-printer";print("assets/sample.pdf").then(console.log);
```## API
### `.print(pdf[, options]) => Promise`
A function that prints your file.
**Arguments**
1. `pdf` (`string`, required): A path to the file you want to print. An error will be thrown if the PDF is not specified or not found.
2. `options` (`Object`, optional):
- `printer` ( `string`, optional): Sends the file to the specified printer.
- `pages` (`string`, optional): Specifies which pages to print in the PDF document.
- `subset` (`string`, optional): Prints odd pages only when the value is `odd`, and even pages only when it is `even`.
- `orientation` (`string`, optional): Provides 90-degree rotation of contents (NOT the rotation of paper which must be pre-set by the choice of printer defaults).
- `scale` (`string`, optional): Supported names are `noscale`, `shrink`, and `fit`.
- `monochrome` (`boolean`, optional): Prints the document in black and white. The default value is `false`.
- `side` (`string`, optional): Supported names are `duplex`, `duplexshort`, `duplexlong`, and `simplex`.
- `bin` (`string`, optional): Select tray to print to. Number or name.
- `paperSize` (`string`, optional): Specifies the paper size. `A2`, `A3`, `A4`, `A5`, `A6`, `letter`, `legal`, `tabloid`, `statement`, or a name selectable from your printer settings.
- `silent` (`boolean`, optional): Silences error messages.
- `printDialog` (`boolean`, optional): Displays the print dialog for all the files indicated on this command line.
- `copies`(`number`, optional): Specifies how many copies will be printed.**Returns**
`Promise`: A Promise that resolves with `undefined`.
**Examples**
To print a file to the default printer, use the following code:
```javascript
import { print } from "pdf-to-printer";print("assets/sample.pdf").then(console.log);
```To print to a specific printer:
```javascript
import { print } from "pdf-to-printer";const options = {
printer: "Zebra",
};print("assets/pdf-sample.pdf", options).then(console.log);
```Here is an example with a few print settings. It will print pages 1, 3, and 5, and scale them so that they fit into the printable area of the paper.
```javascript
import { print } from "pdf-to-printer";const options = {
printer: "Zebra",
pages: "1-3,5",
scale: "fit",
};print("assets/pdf-sample.pdf", options).then(console.log);
```### `.getPrinters() => Promise`
A function to get a list of available printers.
**Returns**
`Promise`: a Promise that resolves with a list of available printers.
**Examples**
```javascript
import { getPrinters } from "pdf-to-printer";getPrinters().then(console.log);
```### `.getDefaultPrinter() => Promise`
A function to get the default printer information.
**Returns**
`Promise`: a Promise that resolves with the default printer information, or `null` if there is no default printer.
**Examples**
```javascript
import { getDefaultPrinter } from "pdf-to-printer";getDefaultPrinter().then(console.log);
```## License
[MIT](LICENSE)