You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|margin |number or array |0 |PDF margin (in jsPDF units). Can be a single number, `[vMargin, hMargin]`, or `[top, left, bottom, right]`. |
112
-
|filename |string |'file.pdf' |The default filename of the exported PDF. |
113
-
|image |object |{type: 'jpeg', quality: 0.95} |The image type and quality used to generate the PDF. See the Extra Features section below. |
114
-
|enableLinks |boolean |true |If enabled, PDF hyperlinks are automatically added ontop of all anchor tags. |
115
-
|html2canvas |object |{ } |Configuration options sent directly to `html2canvas` ([see here](https://html2canvas.hertzen.com/configuration) for usage).|
116
-
|jsPDF |object |{ } |Configuration options sent directly to `jsPDF` ([see here](http://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html) for usage).|
|margin |number or array |`0`|PDF margin (in jsPDF units). Can be a single number, `[vMargin, hMargin]`, or `[top, left, bottom, right]`. |
112
+
|filename |string |`'file.pdf'`|The default filename of the exported PDF. |
113
+
|pagebreak |object |`{mode: ['css', 'legacy']}`|Controls the pagebreak behaviour on the page. See [Page-breaks](#page-breaks) below. |
114
+
|image |object |`{type: 'jpeg', quality: 0.95}`|The image type and quality used to generate the PDF. See [Image type and quality](#image-type-and-quality) below.|
115
+
|enableLinks |boolean |`true`|If enabled, PDF hyperlinks are automatically added ontop of all anchor tags. |
116
+
|html2canvas |object |`{ }`|Configuration options sent directly to `html2canvas` ([see here](https://html2canvas.hertzen.com/configuration) for usage).|
117
+
|jsPDF |object |`{ }`|Configuration options sent directly to `jsPDF` ([see here](http://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html) for usage).|
117
118
118
119
### Page-breaks
119
120
120
-
You may add `html2pdf`-specific page-breaks to your document by adding the CSS class `html2pdf__page-break` to any element (normally an empty `div`). For React elements, use `className=html2pdf__page-break`. During PDF creation, these elements will be given a height calculated to fill the remainder of the PDF page that they are on. Example usage:
121
+
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).
121
122
122
-
```html
123
-
<divid="element-to-print">
124
-
<span>I'm on page 1!</span>
125
-
<divclass="html2pdf__page-break"></div>
126
-
<span>I'm on page 2!</span>
127
-
</div>
123
+
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).
|mode |string or array |`['css', 'legacy']`|The mode(s) on which to automatically add page-breaks. One or more of `'avoid-all'`, `'css'`, and `'legacy'`. |
130
+
|before |string or array |`[]`|CSS selectors for which to add page-breaks before each element. Can be a specific element with an ID (`'#myID'`), all elements of a type (e.g. `'img'`), all of a class (`'.myClass'`), or even `'*'` to match every element. |
131
+
|after |string or array |`[]`|Like 'before', but adds a page-break immediately after the element. |
132
+
|avoid |string or array |`[]`|Like 'before', but avoids page-breaks on these elements. You can enable this feature on every element using the 'avoid-all' mode. |
133
+
134
+
#### Page-break modes
135
+
136
+
| Mode | Description |
137
+
|-----------|-------------|
138
+
| avoid-all | Automatically adds page-breaks to avoid splitting any elements across pages. |
139
+
| css | Adds page-breaks according to the CSS `break-before`, `break-after`, and `break-inside` properties. Only recognizes `always/left/right` for before/after, and `avoid` for inside. |
140
+
| legacy | Adds page-breaks after elements with class `html2pdf__page-break`. This feature may be removed in the future. |
141
+
142
+
#### Example usage
143
+
144
+
```js
145
+
// Avoid page-breaks on all elements, and add one before #page2el.
0 commit comments