html-to-printer
v1.0.1
Published
Print custom HTML on the client-side
Downloads
1,209
Readme
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:
- creating an element containing the HTML string,
- hiding everything else,
- opening print preview which displays just the newly created element, and
- 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.