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.
npm install --save html-to-printer
import { print } from 'html-to-printer'
print(`<div class="report-printout"> ... </div>`)
It does this by:
- creating an element containing the HTML string,
- hiding everything else for the print media query,
- opening print preview to display just the newly created element, and
- removing the element and putting everything else back to normal.
Some of this cleverness is achieved with print/screen media queries.