Custom Webpage Printing library In Pure JavaScript – Print.js

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

Preview:

Custom Webpage Printing library In Pure JavaScript – Print.js

Description:

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.

printJS('doc.pdf')

Print specific part of your webpage.

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

Print an image from your webpage.

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

All possible configuration options.

printJS(SELECTOR, {
  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: ''
});

Changelog:

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

11/21/2018

  • Fix isChrome check

10/17/2018

  • fix html print bug in safari

10/12/2018

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

09/22/2018

  • v1.5.2: set window.printJS

07/20/2018

  • remove console log

07/01/2018

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

06/06/2018

  • update collectStyles match, skip empty properties

05/27/2018

  • clean blob url after print

05/25/2018

  • improve html style processing

You Might Be Interested In:


Leave a Reply