Custom Webpage Printing library In Pure JavaScript – Print.js

Category: Javascript , Recommended | May 27, 2019
Author: crabbly
Views Total: 2,598 views
Official Page: Go to website
Last Update: May 27, 2019
License: MIT


Custom Webpage Printing library In Pure JavaScript – Print.js


Print.js is a pure JavaScript library which helps you print any elements (pdfs, images, html elements or json data objects) from your webpages & files.

Install it via NPM:

$ npm install print.js

How to use it:

Import the print.js into your web project or directly include the JavaScript file  onto your webpage.

<script src="print.js"></script>

Print a file (e.g. pdf) that is stored in your web server.


Print specific part of your webpage.

<div id="printJS-html">
printJS('printJS-html', 'html')

Print an image from your webpage.

printJS('image.jpg', 'image');

All possible configuration options.

  printable: null, // Document source: pdf or image url, html element id or json data object.
  type: 'pdf', // 'pdf', 'html', 'image', 'raw-html', and 'json'
  header: null, // header content
  maxWidth: 800,
  font: 'TimesNewRoman',
  font_size: '12pt',
  honorMarginPadding: true,
  honorColor: false,
  properties: null, // Used when printing JSON. These are the object property names.
  showModal: false,
  modalMessage: 'Retrieving Document...',
  frameId: 'printJS',
  border: true,
  htmlData: ''


v1.0.61 (05/27/2019)

  • Add check for IOS Chrome method to browser.js

v1.0.59 (05/26/2019)

  • Add custom html deep clone function
  • Add support for select element (copy user selected option / state)
  • Add canvas element support
  • Prevent oversized images from being cut off if no style is passed

v1.0.58 (05/24/2019)

  • Updated Typescript Interface with base64
  • Fixed issue with image print results showing wrong image order
  • Open base64 pdf documents into new tags in unsupported browsers

v1.0.57 (05/22/2019)

  • Prevent images from printing in wrong order

v1.0.56 (05/14/2019)

  • Update TypeScript interface.
  • The header has been updated to support HTML.

v1.0.55 (03/31/2019)

  • Add onBrowserIncompatible hook
  • Better type script support
  • Updated dependencies
  • PDF print will always preload file before firing job
  • Support base64 pdf print

v1.0.54 (03/28/2019)

  • Add option to print raw html

v1.0.54 (03/27/2019)

  • Updated Typescript interface
  • Fixes Chrome detection
  • Fixes HTML print bug
  • Fixes issue when setting JSON column size


  • Fix isChrome check


  • fix html print bug in safari


  • v1.5.52: fix issue when setting JSON column size


  • v1.5.2: set window.printJS


  • remove console log


  • Adding the functionality to read the properties as an array of objects


  • update collectStyles match, skip empty properties


  • clean blob url after print


  • improve html style processing

You Might Be Interested In:

Leave a Reply