Skip to content

Commit 735aa38

Browse files
committed
Merge branch 'develop'
2 parents 9bbe4b3 + 451eee7 commit 735aa38

File tree

3 files changed

+60
-22
lines changed

3 files changed

+60
-22
lines changed

README.md

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# html2pdf
1+
# html2pdf.js
22

3-
html2pdf converts any webpage or element into a printable PDF entirely client-side using [html2canvas](https://github.com/niklasvh/html2canvas) and [jsPDF](https://github.com/MrRio/jsPDF).
3+
html2pdf.js converts any webpage or element into a printable PDF entirely client-side using [html2canvas](https://github.com/niklasvh/html2canvas) and [jsPDF](https://github.com/MrRio/jsPDF).
44

55
## Table of contents
66

@@ -32,7 +32,7 @@ html2pdf converts any webpage or element into a printable PDF entirely client-si
3232

3333
#### HTML
3434

35-
The simplest way to use html2pdf is to download `dist/html2pdf.bundle.min.js` to your project folder and include it in your HTML with:
35+
The simplest way to use html2pdf.js is to download `dist/html2pdf.bundle.min.js` to your project folder and include it in your HTML with:
3636

3737
```html
3838
<script src="html2pdf.bundle.min.js"></script>
@@ -42,17 +42,17 @@ The simplest way to use html2pdf is to download `dist/html2pdf.bundle.min.js` to
4242

4343
#### NPM
4444

45-
Install html2pdf and its dependencies using NPM with `npm install --save html2pdf.js` (make sure to include `.js` in the package name).
45+
Install html2pdf.js and its dependencies using NPM with `npm install --save html2pdf.js` (make sure to include `.js` in the package name).
4646

47-
*Note: You can use NPM to create your project, but html2pdf **will not run in Node.js**, it must be run in a browser.*
47+
*Note: You can use NPM to create your project, but html2pdf.js **will not run in Node.js**, it must be run in a browser.*
4848

4949
#### Bower
5050

51-
Install html2pdf and its dependencies using Bower with `bower install --save html2pdf.js` (make sure to include `.js` in the package name).
51+
Install html2pdf.js and its dependencies using Bower with `bower install --save html2pdf.js` (make sure to include `.js` in the package name).
5252

5353
#### Console
5454

55-
If you're on a webpage that you can't modify directly and wish to use html2pdf to capture a screenshot, you can follow these steps:
55+
If you're on a webpage that you can't modify directly and wish to use html2pdf.js to capture a screenshot, you can follow these steps:
5656

5757
1. Open your browser's console (instructions for different browsers [here](https://webmasters.stackexchange.com/a/77337/94367)).
5858
2. Paste in this code:
@@ -65,11 +65,11 @@ If you're on a webpage that you can't modify directly and wish to use html2pdf t
6565
}
6666
addScript('https://raw.githack.com/eKoopmans/html2pdf/master/dist/html2pdf.bundle.js');
6767
```
68-
3. You may now execute html2pdf commands directly from the console. To capture a default PDF of the entire page, use `html2pdf(document.body)`.
68+
3. You may now execute html2pdf.js commands directly from the console. To capture a default PDF of the entire page, use `html2pdf(document.body)`.
6969

7070
## Usage
7171

72-
Once installed, html2pdf is ready to use. The following command will generate a PDF of `#element-to-print` and prompt the user to save the result:
72+
Once installed, html2pdf.js is ready to use. The following command will generate a PDF of `#element-to-print` and prompt the user to save the result:
7373

7474
```js
7575
var element = document.getElementById('element-to-print');
@@ -78,7 +78,7 @@ html2pdf(element);
7878

7979
### Advanced usage
8080

81-
Every step of html2pdf is configurable, using its new Promise-based API. If html2pdf is called without arguments, it will return a `Worker` object:
81+
Every step of html2pdf.js is configurable, using its new Promise-based API. If html2pdf.js is called without arguments, it will return a `Worker` object:
8282

8383
```js
8484
var worker = html2pdf(); // Or: var worker = new html2pdf.Worker;
@@ -93,7 +93,7 @@ var worker = html2pdf().from(element).save();
9393

9494
#### Workflow
9595

96-
The basic workflow of html2pdf tasks (enforced by the prereq system) is:
96+
The basic workflow of html2pdf.js tasks (enforced by the prereq system) is:
9797

9898
```
9999
.from() -> .toContainer() -> .toCanvas() -> .toImg() -> .toPdf() -> .save()
@@ -128,7 +128,7 @@ A few aliases are also provided for convenience:
128128
129129
## Options
130130
131-
html2pdf can be configured using an optional `opt` parameter:
131+
html2pdf.js can be configured using an optional `opt` parameter:
132132
133133
```js
134134
var element = document.getElementById('element-to-print');
@@ -161,9 +161,9 @@ The `opt` parameter has the following optional fields:
161161

162162
### Page-breaks
163163

164-
html2pdf has the ability to automatically add page-breaks to clean up your document. Page-breaks can be added by CSS styles, set on individual elements using selectors, or avoided from breaking inside all elements (`avoid-all` mode).
164+
html2pdf.js has the ability to automatically add page-breaks to clean up your document. Page-breaks can be added by CSS styles, set on individual elements using selectors, or avoided from breaking inside all elements (`avoid-all` mode).
165165

166-
By default, html2pdf will respect most CSS [`break-before`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-before), [`break-after`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-after), and [`break-inside`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-inside) rules, and also add page-breaks after any element with class `html2pdf__page-break` (for legacy purposes).
166+
By default, html2pdf.js will respect most CSS [`break-before`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-before), [`break-after`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-after), and [`break-inside`](https://developer.mozilla.org/en-US/docs/Web/CSS/break-inside) rules, and also add page-breaks after any element with class `html2pdf__page-break` (for legacy purposes).
167167

168168
#### Page-break settings
169169

@@ -218,7 +218,7 @@ The Worker object returned by `html2pdf()` has a built-in progress-tracking mech
218218

219219
## Dependencies
220220

221-
html2pdf depends on the external packages [html2canvas](https://github.com/niklasvh/html2canvas), [jsPDF](https://github.com/MrRio/jsPDF), and [es6-promise](https://github.com/stefanpenner/es6-promise). These dependencies are automatically loaded when using NPM or the bundled package.
221+
html2pdf.js depends on the external packages [html2canvas](https://github.com/niklasvh/html2canvas), [jsPDF](https://github.com/MrRio/jsPDF), and [es6-promise](https://github.com/stefanpenner/es6-promise). These dependencies are automatically loaded when using NPM or the bundled package.
222222

223223
If using the unbundled `dist/html2pdf.min.js` (or its un-minified version), you must also include each dependency. Order is important, otherwise html2canvas will be overridden by jsPDF's own internal implementation:
224224

@@ -233,11 +233,40 @@ If using the unbundled `dist/html2pdf.min.js` (or its un-minified version), you
233233

234234
### Issues
235235

236-
When submitting an issue, please provide reproducible code that highlights the issue, preferably by creating a fork of [this template jsFiddle](https://jsfiddle.net/u6o6ne41/) (which has html2pdf already loaded). Remember that html2pdf uses [html2canvas](https://github.com/niklasvh/html2canvas) and [jsPDF](https://github.com/MrRio/jsPDF) as dependencies, so it's a good idea to check each of those repositories' issue trackers to see if your problem has already been addressed.
236+
When submitting an issue, please provide reproducible code that highlights the issue, preferably by creating a fork of [this template jsFiddle](https://jsfiddle.net/u6o6ne41/) (which has html2pdf.js already loaded). Remember that html2pdf.js uses [html2canvas](https://github.com/niklasvh/html2canvas) and [jsPDF](https://github.com/MrRio/jsPDF) as dependencies, so it's a good idea to check each of those repositories' issue trackers to see if your problem has already been addressed.
237+
238+
#### Known issues
239+
240+
1. **Rendering:** The rendering engine html2canvas isn't perfect (though it's pretty good!). If html2canvas isn't rendering your content correctly, I can't fix it.
241+
- You can test this with something like [this fiddle](https://jsfiddle.net/eKoopmans/z1rupL4c/), to see if there's a problem in the canvas creation itself.
242+
243+
2. **Node cloning (CSS etc):** The way html2pdf.js clones your content before sending to html2canvas is buggy. A fix is currently being developed - try out:
244+
- direct file: Go to [html2pdf.js/bugfix/clone-nodes-BUILD](/eKoopmans/html2pdf.js/tree/bugfix/clone-nodes-BUILD) and replace the files in your project with the relevant files (e.g. `dist/html2pdf.bundle.js`)
245+
- npm: `npm install eKoopmans/html2pdf.js#bugfix/clone-nodes-BUILD`
246+
- Related project: [Bugfix: Cloned nodes](https://github.com/eKoopmans/html2pdf.js/projects/9)
247+
248+
3. **Resizing:** Currently, html2pdf.js resizes the root element to fit onto a PDF page (causing internal content to "reflow").
249+
- This is often desired behaviour, but not always.
250+
- There are plans to add alternate behaviour (e.g. "shrink-to-page"), but nothing that's ready to test yet.
251+
- Related project: [Feature: Single-page PDFs](https://github.com/eKoopmans/html2pdf.js/projects/1)
252+
253+
4. **Rendered as image:** html2pdf.js renders all content into an image, then places that image into a PDF.
254+
- This means text is *not selectable or searchable*, and causes large file sizes.
255+
- This is currently unavoidable, however recent improvements in jsPDF mean that it may soon be possible to render straight into vector graphics.
256+
- Related project: [Feature: New renderer](https://github.com/eKoopmans/html2pdf.js/projects/4)
257+
258+
5. **Promise clashes:** html2pdf.js relies on specific Promise behaviour, and can fail when used with custom Promise libraries.
259+
- In the next release, Promises will be sandboxed in html2pdf.js to remove this issue.
260+
- Related project: [Bugfix: Sandboxed promises](https://github.com/eKoopmans/html2pdf.js/projects/11)
261+
262+
6. **Maximum size:** HTML5 canvases have a [maximum height/width](https://stackoverflow.com/a/11585939/4080966). Anything larger will fail to render.
263+
- This is a limitation of HTML5 itself, and results in large PDFs rendering completely blank in html2pdf.js.
264+
- The jsPDF canvas renderer (mentioned in Known Issue #4) may be able to fix this issue!
265+
- Related project: [Bugfix: Maximum canvas size](https://github.com/eKoopmans/html2pdf.js/projects/5)
237266

238267
### Tests
239268

240-
html2pdf is currently sorely lacking in unit tests. Any contributions or suggestions of automated (or manual) tests are welcome. This is high on the to-do list for this project.
269+
html2pdf.js is currently sorely lacking in unit tests. Any contributions or suggestions of automated (or manual) tests are welcome. This is high on the to-do list for this project.
241270

242271
### Pull requests
243272

@@ -247,8 +276,17 @@ If you want to create a new feature or bugfix, please feel free to fork and subm
247276

248277
[Erik Koopmans](https://github.com/eKoopmans)
249278

279+
#### Contributors
280+
281+
- [@WilcoBreedt](https://github.com/WilcoBreedt)
282+
- [@Ranger1230](https://github.com/Ranger1230)
283+
284+
#### Special thanks
285+
286+
- [Sauce Labs](https://saucelabs.com/) for unit testing.
287+
250288
## License
251289

252290
[The MIT License](http://opensource.org/licenses/MIT)
253291

254-
Copyright (c) 2017 Erik Koopmans <[http://www.erik-koopmans.com/](http://www.erik-koopmans.com/)>
292+
Copyright (c) 2017-2019 Erik Koopmans <[http://www.erik-koopmans.com/](http://www.erik-koopmans.com/)>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"browser": "dist/html2pdf.js",
88
"repository": {
99
"type": "git",
10-
"url": "git+https://github.com/eKoopmans/html2pdf.git"
10+
"url": "git+https://github.com/eKoopmans/html2pdf.js.git"
1111
},
1212
"keywords": [
1313
"javascript",
@@ -23,9 +23,9 @@
2323
},
2424
"license": "MIT",
2525
"bugs": {
26-
"url": "https://github.com/eKoopmans/html2pdf/issues"
26+
"url": "https://github.com/eKoopmans/html2pdf.js/issues"
2727
},
28-
"homepage": "https://github.com/eKoopmans/html2pdf",
28+
"homepage": "https://ekoopmans.github.io/html2pdf.js/",
2929
"dependencies": {
3030
"es6-promise": "^4.2.5",
3131
"html2canvas": "^1.0.0-alpha.12",

src/worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Worker.prototype.toPdf = function toPdf() {
195195

196196
for (var page=0; page<nPages; page++) {
197197
// Trim the final page to reduce file size.
198-
if (page === nPages-1) {
198+
if (page === nPages-1 && pxFullHeight % pxPageHeight !== 0) {
199199
pageCanvas.height = pxFullHeight % pxPageHeight;
200200
pageHeight = pageCanvas.height * this.prop.pageSize.inner.width / pageCanvas.width;
201201
}

0 commit comments

Comments
 (0)