jQuery printing plugin; print specific elements on a page – printThis

In this post I am going to share simple jQuery plugin which help you to print any html page or specific content or element of page just one click. This plugin is loaded lot’s of feature which help you to customize the printing methods and other things.

Features:

  • Print specific & multiple DOM elements
  • Preserve page CSS/styling
    ** or add new CSS; the world is your oyster!
  • Preserve form entries
  • Canvas support


Libraries

Load the jQuery and printThis JS Library on Page.

<!-- jQuery -->
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <!-- printThis -->
  <script type="text/javascript" src="printThis.js"></script>

Basic Example
use the very basic method the print selected element.

$('selector').printThis();

Advanced Features:

$('#kitty-one, #kitty-two, #kitty-three').printThis({
    importCSS: false,
    loadCSS: "",
    header: "<h1>Look at all of my kitties!</h1>"
});

header & footer

$('#mySelector').printThis({
    header: "<h1>Amazing header</h1>"
});
 
$('#mySelector').printThis({
    footer: $('.hidden-print-header-content')
});


Here are the list of options you can use to customize the plugins.

$("#mySelector").printThis({
    debug: false,               
    importCSS: true,            
    importStyle: false,         
    printContainer: true,       
    loadCSS: "",                
    pageTitle: "",              
    removeInline: false,        
    removeInlineSelector: "*",  
    printDelay: 333,            
    header: null,               
    footer: null,               
    base: false,                
    formValues: true,           
    canvas: false,              
    doctypeString: '...',       
    removeScripts: false,       
    copyTagClasses: false,      // copy classes from the html & body tag
    beforePrintEvent: null,     
    beforePrint: null,          
    afterPrint: null            
});

See live demo and download source code.

DEMO | DOWNLOAD

This awesome plugin is developed by tameemsafi. Visit their official github repository for more information and follow for future updates.