Giter Site home page Giter Site logo

raminsherwani / printthis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jasonday/printthis

0.0 2.0 0.0 577 KB

jQuery printing plugin; print specific elements on a page

Home Page: https://jasonday.github.io/printThis/

License: MIT License

HTML 44.08% JavaScript 55.92%

printthis's Introduction

npm version

printThis

Printing plug-in for jQuery

Features

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

Usage

Basic

$('selector').printThis();

Advanced Features

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

Troubleshooting

Check the printThis wiki for common issues and questions

Covers common issues related to styling and printing limitations regarding page breaks

Options

debug

Debug leaves the iframe visible on the page after printThis runs, allowing you to inspect the markup and CSS.

importCSS

Copy CSS <link> tags to the printThis iframe. On by default.

importStyle

Copy CSS <style> tags to the printThis iframe. Off by default.

printContainer

Includes the markup of the selected container, not just its contents. On by default.

loadCSS

Provide a URL for an additional stylesheet to the printThis iframe. Empty string (off) by default.

pageTitle

Use a custom page title on the iframe. This may be reflected on the printed page, depending on settings. Blank by default.

removeInline

Eliminates any inline style attributes from the content. Off by default.

removeInlineSelector

Filter which inline style attributes to remove. Requires removeInline to be true. Accepts custom CSS/jQuery selectors. Default is "*"

printDelay

The amount of time to wait before calling print() in the printThis iframe. Defaults to 333 milliseconds. Appropriate values depend heavily on the content and network performance. Graphics heavy, slow, or uncached content may need extra time to load.

header & footer

A string or jQuery object to prepend or append to the printThis iframe content. null by default.

$('#mySelector').printThis({
    header: "<h1>Amazing header</h1>"
});

$('#mySelector').printThis({
    footer: $('.hidden-print-header-content')
});

As of 1.9.1, jQuery objects are cloned rather than moved.

base

The base option allows several behaviors. By default it is false, meaning a the current document will be set as the base URL.

If set to true, a <base> attribute will be set if one exists on the page. If none is found, the tag is omitted, which may be suitable for pages with Fully Qualified URLs.

When passed as a string, it will be used as the href attribute of a <base> tag.

formValues

This setting copies the current values of form elements into the printThis iframe. On by default.

canvas

As of 1.9.0 you may be able to duplicate canvas elements to the printThis iframe. Disabled by default. This has received only limited testing and so may not work in all browsers and situations.

As of 1.12.2 you can call printThis directly on a canvas element.

doctypeString

A doctype string to use on the printThis iframe. Defaults to the HTML5 doctype.

removeScripts

Deletes script tags from the content to avoid errors or unexpected behavior during print. Disabled by default.

copyTagClasses: false

Copies classes from the body and html tags into the printThis iframe.
Accepts true or test for the strings "b" and "h" for the body and html tags, respectively.
Disabled by default.

beforePrintEvent: null

Function to run inside the iframe before the print occurs.
This function has not been validated on all browsers.

beforePrint: null

Function called before the iframe is populated with content.

afterPrint: null

Function called after the print and before the iframe is removed from the page.
This is called even if debug: true, which does not remove the iframe.

All Options

$("#mySelector").printThis({
    debug: false,               // show the iframe for debugging
    importCSS: true,            // import parent page css
    importStyle: false,         // import style tags
    printContainer: true,       // print outer container/$.selector
    loadCSS: "",                // path to additional css file - use an array [] for multiple
    pageTitle: "",              // add title to print page
    removeInline: false,        // remove inline styles from print elements
    removeInlineSelector: "*",  // custom selectors to filter inline styles. removeInline must be true
    printDelay: 333,            // variable print delay
    header: null,               // prefix to html
    footer: null,               // postfix to html
    base: false,                // preserve the BASE tag or accept a string for the URL
    formValues: true,           // preserve input/form values
    canvas: false,              // copy canvas content
    doctypeString: '...',       // enter a different doctype for older markup
    removeScripts: false,       // remove script tags from print content
    copyTagClasses: false,      // copy classes from the html & body tag
    beforePrintEvent: null,     // function for printEvent in iframe
    beforePrint: null,          // function called before iframe is filled
    afterPrint: null            // function called before iframe is removed
});

Please read

  • "It's not working" without any details is not a valid issue and will be closed
  • A url, or html file, is necessary to debug. Due to the complexities of printing and this plugin, an example is the best way to debug
  • When troubleshooting, set debug: true and inspect the iframe. Please report your findings when reporting an issue
  • Every user should be active in the debugging process

ToDo:

  • Look at alternative to setTimeout ($.deferred?)

printthis's People

Contributors

jasonday avatar oculus42 avatar klarkc avatar geezerdiamond avatar caseyjhol avatar subtletree avatar eakkew avatar flashnet69 avatar alandmoore avatar relequestual avatar clavinmacario avatar idkn avatar nip3o avatar 0x6368656174 avatar bryant1410 avatar stritti avatar tanathos avatar

Watchers

James Cloos avatar ramin sherwani avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.