Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 11 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<a href="https://badge.fury.io/js/print-this"><a href="https://opencollective.com/printThis" ><img src="https://opencollective.com/printThis/all/badge.svg?label=financial+contributors" alt="Financial Contributors on Open Collective"/></a> <img src="https://badge.fury.io/js/print-this.svg" alt="npm version" height="18" align="right"></a>

# printThis
Printing plug-in for jQuery
#### [Try the Demo](https://jasonday.github.io/printThis/)
Printing library in vanilla JavaScript
#### [Try the demo](https://jasonday.github.io/printThis/)

> [!CAUTION]
> printThis 3.0 drops the jQuery dependency. Initiating the library utilizes new syntax, although the options remain the same.


## Features
Expand All @@ -17,12 +20,12 @@ Printing plug-in for jQuery
## Usage
### Basic
```javascript
$('selector').printThis();
printThis('selector');
```

### Advanced Features
```javascript
$('#kitty-one, #kitty-two, #kitty-three').printThis({
printThis('#kitty-one, #kitty-two, #kitty-three', {
importCSS: false,
loadCSS: "",
header: "<h1>Look at all of my kitties!</h1>"
Expand Down Expand Up @@ -63,25 +66,15 @@ Eliminates any inline style attributes from the content. Off by default.
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 1000 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.
A string or object to prepend or append to the printThis iframe content. `null` by default.

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

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

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.
Expand All @@ -98,9 +91,6 @@ This setting copies the current values of form elements into the printThis ifram
Canvas elements will be copied to the printThis iframe
and you can call printThis directly on a canvas element if you choose.

#### 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.

Expand All @@ -126,22 +116,20 @@ This is called even if `debug: true`, which does not remove the iframe.

### All Options
```javascript
$("#mySelector").printThis({
printThis("#mySelector", {
debug: false, // show the iframe for debugging
importCSS: true, // import parent page css
importStyle: true, // import style tags
printContainer: true, // print outer container/$.selector
printContainer: true, // print outer container
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: 1000, // 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: true, // copy classes from the html & body tag
copyTagStyles: true, // copy styles from html & body tag (for CSS Variables)
Expand All @@ -157,9 +145,6 @@ $("#mySelector").printThis({
* 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?)

## Contributors

### Code Contributors
Expand All @@ -179,13 +164,3 @@ Become a financial contributor and help us sustain our community. [[Contribute](

Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/printThis/contribute)]

<a href="https://opencollective.com/printThis/organization/0/website"><img src="https://opencollective.com/printThis/organization/0/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/1/website"><img src="https://opencollective.com/printThis/organization/1/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/2/website"><img src="https://opencollective.com/printThis/organization/2/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/3/website"><img src="https://opencollective.com/printThis/organization/3/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/4/website"><img src="https://opencollective.com/printThis/organization/4/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/5/website"><img src="https://opencollective.com/printThis/organization/5/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/6/website"><img src="https://opencollective.com/printThis/organization/6/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/7/website"><img src="https://opencollective.com/printThis/organization/7/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/8/website"><img src="https://opencollective.com/printThis/organization/8/avatar.svg"></a>
<a href="https://opencollective.com/printThis/organization/9/website"><img src="https://opencollective.com/printThis/organization/9/avatar.svg"></a>
8 changes: 4 additions & 4 deletions assets/css/skeleton.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ input[type="submit"].button-primary,
input[type="reset"].button-primary,
input[type="button"].button-primary {
color: #FFF;
background-color: #009FD4;
border-color: #009FD4; }
background-color: #054fb9;
border-color: #052b5f; }
.button.button-primary:hover,
button.button-primary:hover,
input[type="submit"].button-primary:hover,
Expand All @@ -248,8 +248,8 @@ input[type="submit"].button-primary:focus,
input[type="reset"].button-primary:focus,
input[type="button"].button-primary:focus {
color: #FFF;
background-color: #1EAEDB;
border-color: #1EAEDB; }
background-color: #052b5f;
border-color: #052b5f; }


/* Forms
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "printThis",
"description": "Printing plug-in for jQuery",
"description": "Printing library",
"main": "printThis.js",
"authors": [
"Jason Day"
],
"license": "MIT",
"keywords": [
"print",
"jQuery"
"printing"
],
"homepage": "https://github.com/jasonday/printThis",
"moduleType": [],
Expand Down
146 changes: 75 additions & 71 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,100 +1,104 @@
05/29/2022 Set new defaults
Bumped to 2.0.0
11/28/2025 Reworked to remove jQuery dependency
Solve Android print issues
Bumped to 3.0.0

05/05/2020 Add copyTagStyles behavior proposed by eakkew
Correct year on 1.15.1 changelog entry
Bumped to 1.16.0
05/29/2022 Set new defaults
Bumped to 2.0.0

08/04/2019 Merged beforePrintEvent fix from Uriel2015
Bumped to 1.15.1
05/05/2020 Add copyTagStyles behavior proposed by eakkew
Correct year on 1.15.1 changelog entry
Bumped to 1.16.0

05/15/2019 Added TypeScript definitions from nvirth
Bumped to 1.15.0
08/04/2019 Merged beforePrintEvent fix from Uriel2015
Bumped to 1.15.1

11/03/2018 Added fix for canvas data attribute removal from apires03
Bumped to 1.14.1
05/15/2019 Added TypeScript definitions from nvirth
Bumped to 1.15.0

07/15/2018 Merge support for print event handlers from eakkew
Include fix for CSS Variables (via inline styles set on HTML tag)
Make documentation consistent
Bump to 1.14.0
11/03/2018 Added fix for canvas data attribute removal from apires03
Bumped to 1.14.1

07/15/2018 Merge removeInlineSelector to filter which inline styles are removed from kory75
Remove "experimental" tag from Canvas support. We're pretty stable at this point
Bumped to 1.13.0
07/15/2018 Merge support for print event handlers from eakkew
Include fix for CSS Variables (via inline styles set on HTML tag)
Make documentation consistent
Bump to 1.14.0

03/18/2018 Fixed importStyle
Bumped to 1.12.3
07/15/2018 Merge removeInlineSelector to filter which inline styles are removed from kory75
Remove "experimental" tag from Canvas support. We're pretty stable at this point
Bumped to 1.13.0

01/10/2018 Merged fix for top-level Canvas support
Bumped to 1.12.2
03/18/2018 Fixed importStyle
Bumped to 1.12.3

12/17/2017 Merged fix for jQuery version limit from nip3o
Bumped to 1.12.1
01/10/2018 Merged fix for top-level Canvas support
Bumped to 1.12.2

10/30/2017 Merged simpler form clone from Subtletree
Updated README to correct 1.9.1 reference to past-tense
Bumped to 1.12.0
12/17/2017 Merged fix for jQuery version limit from nip3o
Bumped to 1.12.1

08/01/2017 Added copyTagClasses, disabled by default, to copy body & html tag classes from the page
Updated README documentation for removeScripts
Updated README to remove old versions number from canvas support to prevent confusion
Bumped to 1.11.0
10/30/2017 Merged simpler form clone from Subtletree
Updated README to correct 1.9.1 reference to past-tense
Bumped to 1.12.0

04/06/2017 Added action, disabled by default, to avoid bringing unwanted scripts into the print iframe.
Removed undocumented helper function $.fn.outer
Reformatted example text with valid JS comments
Bumped to 1.10.0 for new feature (removeScripts)
08/01/2017 Added copyTagClasses, disabled by default, to copy body & html tag classes from the page
Updated README documentation for removeScripts
Updated README to remove old versions number from canvas support to prevent confusion
Bumped to 1.11.0

03/07/2017 Added clone action for header or footer jQuery objects to prevent originals being removed.
Bumped to 1.9.1
04/06/2017 Added action, disabled by default, to avoid bringing unwanted scripts into the print iframe.
Removed undocumented helper function $.fn.outer
Reformatted example text with valid JS comments
Bumped to 1.10.0 for new feature (removeScripts)

01/16/2017 Added experimental canvas copy support.
Added detailed descriptions of advanced options to README
Bumped to 1.9.0 for new feature (canvas).
03/07/2017 Added clone action for header or footer jQuery objects to prevent originals being removed.
Bumped to 1.9.1

01/16/2017 Added footer as proposed in 2015 by @RomainGehrig
Bumped version to 1.8.0 for new feature
Corrected 1.7.1 changelog date to 01/15/2017
01/16/2017 Added experimental canvas copy support.
Added detailed descriptions of advanced options to README
Bumped to 1.9.0 for new feature (canvas).

01/15/2017 Added quoting around values to correct behavior of complex values
Bumped to 1.7.1
01/16/2017 Added footer as proposed in 2015 by @RomainGehrig
Bumped version to 1.8.0 for new feature
Corrected 1.7.1 changelog date to 01/15/2017

12/14/2016 Added support for arbitrary BASE urls.
Bumped to 1.7.0, following semver (new feature).
01/15/2017 Added quoting around values to correct behavior of complex values
Bumped to 1.7.1

12/13/2016 Incremented to 1.6.0 for new base setting.
12/14/2016 Added support for arbitrary BASE urls.
Bumped to 1.7.0, following semver (new feature).

11/23/2016 added new base option. Preserves the BASE tag from the parent page.
12/13/2016 Incremented to 1.6.0 for new base setting.

11/07/2014 Fixed bug; Recent versions of Firefox are not applying the parent document domain to
elements without fully qualified srcs. Added a <base>.
11/23/2016 added new base option. Preserves the BASE tag from the parent page.

10/25/2014 Fixed bug; <styles> being copied to print iframe were being removed from parent
Added ability to use loadCSS with multiple stylesheets
11/07/2014 Fixed bug; Recent versions of Firefox are not applying the parent document domain to
elements without fully qualified srcs. Added a <base>.

09/21/2014 added import of style tags
10/25/2014 Fixed bug; <styles> being copied to print iframe were being removed from parent
Added ability to use loadCSS with multiple stylesheets

05/12/2014 added formValues option. Preserves entered form data for print.
09/21/2014 added import of style tags

10/11/2013 added printDelay option. Sometimes 333 isn't enough
added header option -- inserts html before selected content, for images ensure to use full path
05/12/2014 added formValues option. Preserves entered form data for print.

03/08/2013 added option to remove inline styles from print elements
10/11/2013 added printDelay option. Sometimes 333 isn't enough
added header option -- inserts html before selected content, for images ensure to use full path

03/04/2013 fixed showstopper with IE and document.domain
major rework of file structure/methods
added "pageTitle" option
some minor rework of other areas
03/08/2013 added option to remove inline styles from print elements

11/23/2012 fixed showstopper with Firefox:
moved variable $doc to within setTimeout function
03/04/2013 fixed showstopper with IE and document.domain
major rework of file structure/methods
added "pageTitle" option
some minor rework of other areas

11/11/2012 reworked plugin to use a jQuery object
removed document.write
added setTimeout (waits for iframe to full render before action)
11/23/2012 fixed showstopper with Firefox:
moved variable $doc to within setTimeout function

11/07/2012 added support for loading css files
removed Opera option, left in by default
added timeout to remove iframe after 60 seconds
added unique name to iframe
11/11/2012 reworked plugin to use a jQuery object
removed document.write
added setTimeout (waits for iframe to full render before action)

11/07/2012 added support for loading css files
removed Opera option, left in by default
added timeout to remove iframe after 60 seconds
added unique name to iframe
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "jasonday/print-this",
"description": "Printing plug-in for jQuery",
"description": "Printing library in javascript for printing specific parts of a page",
"version": "3.0.0",
"type": "library",
"require": {
"components/jquery": ">=1.11"
},
"license": "MIT",
"authors": [
Expand Down
Loading