1.0.1 • Published 7 years ago

html-to-printer v1.0.1

Weekly downloads
230
License
Apache-2.0
Repository
-
Last release
7 years ago

html-to-printer

Print custom HTML on the client-side

Exposes a function that takes in a HTML string, and opens a print preview window with its contents, respecting the CSS of that page.

Installation

npm install --save html-to-printer

Usage

import { print } from 'html-to-printer'

print(`<div class="report-printout"> ... </div>`)

How it works

It does this by:

  1. creating an element containing the HTML string,
  2. hiding everything else,
  3. opening print preview which displays just the newly created element, and
  4. removing the element and putting everything else back to normal.

This generally happens fast enough that you don't see any flicker in your browser window.