Print.js
A tiny javascript library to help printing from the web.
A small JavaScript library that lets you print just a specific part of a web page, such as a PDF, image, HTML form, or page section, instead of printing the entire page.
Print.js is a small JavaScript library that makes it easier to trigger print dialogs from a web page. Instead of printing the entire page, it lets you target specific things, like a PDF file, an HTML form, an image, or a section of the page, and send just that to the printer. The goal is to keep the library lightweight and focused on one job.
To add it to a project, you install it through npm or yarn, two common tools developers use to manage JavaScript code packages. You import it into your code with one line, and from there you call it whenever you want to offer a print action. Full usage examples and configuration options live on the project's external documentation site at printjs.crabbly.com rather than in this repository.
The README is intentionally sparse. It covers installation steps, points to the documentation website for actual usage, and explains how contributors can report bugs or submit improvements. Bug reports should include a reproducible example, and the maintainers prefer keeping the library small rather than adding many new features.
For developers who want to work on the library itself, the process is to install dependencies with npm, run a watch command during development, and use the built-in test suite to check for problems. Tests are written with Jasmine, a JavaScript testing framework, and run through Karma, a test runner. The code follows the JavaScript Standard style guide, so style issues are caught alongside logic errors during testing.
The project is MIT licensed, which means it is free to use in personal and commercial projects without restriction.
Where it fits
- Add a print button that sends only an invoice or receipt section of a page to the printer
- Let users print a completed HTML form without the surrounding navigation and page layout
- Trigger a print dialog for a specific PDF displayed inside a web application
- Print a single product image from a page without extra content