Select a demo to see the code example and the result. Please allow window pop-ups if any problems occured
ezPrintJS is a tiny JavaScript library which allows to make pretty-looking printable pages without the need of modification even single line of existing code in your CSS styles and HTML markup. You are free to precisely customize content that your visitors will see on the paper.
See the minimun example below:
<!-- optional: add polyfill BEFORE ezPrintJS if you're willing to support outdated (pre-ES6 era) browsers -->
<script src="/path/to/polyfill.min.js"></script>
<!-- include ezPrintJS library... -->
<script src="/path/to/ezprintjs.min.js"></script>
<!-- ...and set trigger to run ezPrintJS in plain JavaScript... -->
<script>
document.querySelector('#myPrintButton').addEventListener('click', function() {
ezPrintJS({
target: '#myContentID',
// any combination of other options. See examples and docs!
})
})
</script>
<!-- ...or even shorter with jQuery -->
<script>
$('#myPrintButton').click(function() {
ezPrintJS({
target: '#myContentID',
// any combination of other options. See examples and docs!
})
})
</script>
Option | Data type | Description |
---|---|---|
target | string |
The only required parameter. 'Target' should be valid CSS selector. Forbidden target tags are: 'LINK', 'TITLE', 'HEAD', 'META', 'BASE', 'BASEFONT', 'SCRIPT', 'STYLE', 'NOSCRIPT', 'APPLET'
|
printInIframe | boolean |
Print in hidden iframe without creating new window (v1.1.0) |
setPrintSize | string |
Page size and orientation. See more at: https://developer.mozilla.org/en-US/docs/Web/CSS/@page/size |
beforePrintCb | function |
Callback function, fires before new window will be created. No arguments will be passed |
afterPrintCb | function |
Callback function, fires after print is done or cancelled. No arguments will be passed Effective only with new window prints |
exposeLinkUrls | string |
Extract link href and append it to link title Valid values are:
|
linkTextTemplate | string |
String template for link title extraction, needs '{title}' and '{url}'. Effective only with 'exposeLinkUrls' option enabled
Default template: |
keepSourceCSS | boolean |
Preserve original style/link tags on printing page |
watermarkImageURL | string |
URL for watermark image. Image will be centered and printed on every page with opacity set to 0.25 |
watermarkOpacity | number |
Set custom watermark opacity. Value should be float number between 0 and 1 (v1.1.0) |
headerText | string |
Text for top tagline. Not recommended for multipage prints due overlapping |
footerText | string |
Text for bottom tagline. Not recommended for multipage prints due overlapping |
revealHiddenElements | boolean |
Reset 'display' option for elements with style set to 'display: none;'. Especially useful for printing tabbed content |
printCanvas | boolean |
Try to capture and print 2D content of canvas elements
|
extendScrollableAreas | boolean|string |
Expands vertical scrollable elements Valid values are:
|
scrollableAreasMaxHeight | number |
Limit maximum height (in pixels) of expanded scrollable elements. Effective only with 'extendScrollableAreas' option enabled |
excludeSelectorList | array |
Array of CSS selectors for unwanted elements. Target elements will be hidden in printable page. Note: this option has higher priority over 'revealHiddenElements' |
removeInlineStyles | boolean |
Clean element's inline style |
removeImages | boolean |
Correctly removes images on printing page by replacing them with bordered (1px thickness) squares |
injectCustomStyle | string |
Inject any custom styles in printable page. See 'Demo 15' for more info |
customMethodMap | object |
Most interesting option. This option allows you to take full control over content that user will print Object 'customMethodMap' should contain tag name as key, and array of functions as value Let's say we wish modify all (or some) content wrapped in 'span' and 'figure' tags, then our 'customMethodMap' object will look like:
Rules are dead-simple:
|
v1.1.0 Made by Nedgeva, 2017. Buy at CodeCanyon