print-dom
Version:
Lightweight and fast print tool for browser.
79 lines (54 loc) • 2.73 kB
Markdown
# print-dom
> Lightweight and fast print tool for browser.
[](http://npm-stats.com/~packages/print-dom)
[](https://github.com/zh-rocco/print-dom/stargazers)
[](https://david-dm.org/zh-rocco/print-dom?type=dev)
[](https://www.npmjs.com/package/print-dom)
[](https://github.com/zh-rocco/print-dom/)
[](https://travis-ci.org/zh-rocco/print-dom)
[](https://github.com/zh-rocco/print-dom/blob/master/LICENSE)
## Demo
[Try it out](https://zh-rocco.github.io/print-dom/)
## Advantages
- Simple API.
- Small bundle size: 3.8KB (1.54KB gzipped).
- No dependencies.
- Faster than [print-js](https://github.com/crabbly/Print.js/)
## Installation
```bash
npm i print-dom -S
# OR
yarn add print-dom -S
```
## Usage
```js
import printDOM from "print-dom";
printDOM(document.querySelector("#print"));
```
with options
```js
import printDOM from "print-dom";
printDOM(document.querySelector("#print"), {
noPrint: [".header"],
documentTitle: "Nice!!!",
wrapClass: ".print-wrapper",
style: ".print-wrapper { font-size: 16px; }",
});
```
## Options
| Property | Description | Type | Default |
| :----------------- | :------------------------------------------- | :--------------------------------- | :------------------- |
| noPrint | Ignore list when printing. | `String[]` | `[".no-print"]` |
| documentTitle | Print page's title. | `String` | Parent page's title. |
| style | Custom style. | `String` | `void` |
| wrapClass | Print element's className. | `String` | `void` |
| processor | Process the DOM before print. | `(el: HTMLElement) => HTMLElement` | `void` |
| onPrintDialogClose | Run when the browser print dialog is closed. | `() => void` | `void` |
## Build
```bash
yarn build
```
## Todo
- Add test files.
## License
MIT © [zh-rocco](https://github.com/zh-rocco)