Skip to content

Commit 1daef93

Browse files
jeffsieuHackbrettXXXRui-Jesus
authored
Add margins functionality and autoPaging modes to html function (#2977)
* implement margins that were previously part of the API but had no effect * implement 'slice' and 'text' auto paging modes Co-authored-by: Lukas Hollaender <lukas.hollaender@yworks.com> Co-authored-by: Rui-Jesus <32493599+Rui-Jesus@users.noreply.github.com>
1 parent 574c6f0 commit 1daef93

20 files changed

+455
-53
lines changed

src/modules/context2d.js

Lines changed: 258 additions & 51 deletions
Large diffs are not rendered by default.

src/modules/html.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,13 @@ import { globalObject } from "../libs/globalObject.js";
462462
);
463463
delete options.onrendered;
464464

465-
pdf.context2d.autoPaging = true;
465+
pdf.context2d.autoPaging =
466+
typeof this.opt.autoPaging === "undefined"
467+
? true
468+
: this.opt.autoPaging;
466469
pdf.context2d.posX = this.opt.x;
467470
pdf.context2d.posY = this.opt.y;
471+
pdf.context2d.margin = this.opt.margin;
468472
pdf.context2d.fontFaces = fontFaces;
469473

470474
if (fontFaces) {
@@ -1019,7 +1023,22 @@ import { globalObject } from "../libs/globalObject.js";
10191023
* @param {HTMLElement|string} source The source HTMLElement or a string containing HTML.
10201024
* @param {Object} [options] Collection of settings
10211025
* @param {function} [options.callback] The mandatory callback-function gets as first parameter the current jsPDF instance
1022-
* @param {number|array} [options.margin] Array of margins [left, bottom, right, top]
1026+
* @param {(number|number[])=} [options.margin] Page margins [top, right, bottom, left]. Default is 0.
1027+
* @param {(boolean|'slice'|'text')=} [options.autoPaging] The auto paging mode.
1028+
* <ul>
1029+
* <li>
1030+
* <code>false</code>: Auto paging is disabled.
1031+
* </li>
1032+
* <li>
1033+
* <code>true</code> or <code>'slice'</code>: Will cut shapes or text chunks across page breaks. Will possibly
1034+
* slice text in half, making it difficult to read.
1035+
* </li>
1036+
* <li>
1037+
* <code>'text'</code>: Trys not to cut text in half across page breaks. Works best for documents consisting
1038+
* mostly of a single column of text.
1039+
* </li>
1040+
* </ul>
1041+
* Default is <code>true</code>.
10231042
* @param {string} [options.filename] name of the file
10241043
* @param {HTMLOptionImage} [options.image] image settings when converting HTML to image
10251044
* @param {Html2CanvasOptions} [options.html2canvas] html2canvas options
5.14 KB
Binary file not shown.
24.2 KB
Binary file not shown.
23.8 KB
Binary file not shown.
4.87 KB
Binary file not shown.
3.32 KB
Binary file not shown.

test/reference/html-margin-x-y.pdf

3.49 KB
Binary file not shown.

test/reference/html-margin.pdf

3.49 KB
Binary file not shown.
-788 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)