Print Specific Content While Preserving Styling – Printout.js

Category: Javascript | July 3, 2022
Author:jihad28
Views Total:534 views
Official Page:Go to website
Last Update:July 3, 2022
License:MIT

Preview:

Print Specific Content While Preserving Styling – Printout.js

Description:

Printout.js is a JavaScript printing library to print specific DOM elements while maintaining their visual aspect.

No more printing messy data, with this library, your printer will print clean and well-presented content.

How to use it:

1. Download and load the Printout.js library in the document.

<script src="../printout.js"></script>

2. Print specific content from an element.

printout('selector');

3. Set the title of the page.

printout('selector', {
  pageTitle: window.document.title,
})

4. Determine whether to use the page’s styles.

printout('selector', {
  importCSS: true,
})

5. Or use inline CSS.

printout('selector', {
  inlineStyle: true, 
})

6. Determine whether to auto print when the page is open.

printout('selector', {
  autoPrint: true,
  autoPrintDelay: 1000,
})

7. Specifies the CSS class used to identify elements to be ignored.

printout('selector', {
  noPrintClass: 'no-print',
})

8. Add custom header & footer (string or element) to the Printout.

printout('selector', {
  header: null, 
  footer: null,
})

9. Determine whether to close the window after printing. Default: true.

printout('selector', {
  closeAfterPrint: close,
})

Changelog:

07/03/2022

  • Added Close After Print Option

You Might Be Interested In:


Leave a Reply