explaingit

crabbly/print.js

4,553JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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.

Mindmap

mindmap
  root((print.js))
    What it does
      Targeted printing
      No full-page print
      Single function call
    Supported targets
      HTML elements
      PDF files
      Images
      Forms
    Setup
      npm or yarn install
      Import one line
    Testing
      Jasmine tests
      Karma runner
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a print button that sends only an invoice or receipt section of a page to the printer

USE CASE 2

Let users print a completed HTML form without the surrounding navigation and page layout

USE CASE 3

Trigger a print dialog for a specific PDF displayed inside a web application

USE CASE 4

Print a single product image from a page without extra content

Tech stack

JavaScript

Getting it running

Difficulty · easy Time to first run · 5min
MIT License, use freely in any personal or commercial project without restriction.

In plain English

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.

Copy-paste prompts

Prompt 1
Using Print.js, add a print button to my invoice page that prints only the div with id 'invoice' and not the rest of the navigation or header.
Prompt 2
My web app shows a multi-page PDF in an iframe. How do I use Print.js to let users print just that PDF from a button click?
Prompt 3
Show me how to install Print.js with npm and wire it up so clicking a button triggers printing a specific HTML form.
Prompt 4
I want to print an image from my gallery page using Print.js. Walk me through the setup and the exact function call needed.
Open on GitHub → Explain another repo

← crabbly on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.