rpdasilva / print-html-element

Prints the HTML of a provided element.
MIT License
24 stars 10 forks source link

Print HTML Element

Prints the HTML of a provided element.

Originally forked from jQuery.printElement to remove jQuery dependency.

This fork removes some features while adding others (IE8 support is also removed for now). More features will be added as needed or requested. PR's welcome.

View examples here

Installation

Print HTML Element is available on both NPM and Bower.

npm install print-html-element

bower install print-html-element

Usage

Include

In a CommonJS module system via Browserify or Webpack

    var PHE = require("print-html-element");

Good old-fashioned way

    <script type="text/javascript" src="https://github.com/rpdasilva/print-html-element/raw/master/print-html-element.js"></script>
    // Alias global variable printHtmlElement for purposes of example
    var PHE = printHtmlElement;

Examples

View examples here

    PHE.printElement( document.getElementById('toPrint') );
    PHE.printHtml('<h1>Let\'s print this h1</h1>');

    PHE.printHtml('<h1>Let\'s print this h1</h1>', {templateString: '<header>I\'m part of the template header</header>{{printBody}}<footer>I\'m part of the template footer</footer>'});

An HTML class pe-body is also added to the body of the print area which can be used as an additional style hook (on top of the regular print media query/stylesheet)

Options and methods supported

    opts = {
        printMode: string;
        pageTitle: string;
        templateString: string;
        popupProperties: string;
        stylesheets: string | string[];
        styles: string | string[];
    };

    PHE.printElement( elem, opts ); // Prints a DOM Element
    PHE.printHtml( str, opts ); // Prints an HTML string

Possible future features

License

print-html-element is MIT licensed