Skip to content

Commit 57120de

Browse files
authored
Fix not rendering multiple calls to html() (#3271)
1 parent cda5694 commit 57120de

21 files changed

+13
-2
lines changed

src/modules/html.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,12 @@ import { globalObject } from "../libs/globalObject.js";
494494
)
495495
: options.windowHeight;
496496

497+
pdf.context2d.save(true);
497498
return html2canvas(this.prop.container, options);
498499
})
499500
.then(function toContext2d_post(canvas) {
501+
this.opt.jsPDF.context2d.restore(true);
502+
500503
// Handle old-fashioned 'onrendered' argument.
501504
var onRendered = this.opt.html2canvas.onrendered || function() {};
502505
onRendered(canvas);

test/reference/html-basic.pdf

36 Bytes
Binary file not shown.

test/reference/html-font-faces.pdf

38 Bytes
Binary file not shown.
35 Bytes
Binary file not shown.
42 Bytes
Binary file not shown.
42 Bytes
Binary file not shown.
38 Bytes
Binary file not shown.
34 Bytes
Binary file not shown.

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

34 Bytes
Binary file not shown.

test/reference/html-margin.pdf

34 Bytes
Binary file not shown.

test/reference/html-multiple.pdf

4.51 KB
Binary file not shown.
36 Bytes
Binary file not shown.
Binary file not shown.
36 Bytes
Binary file not shown.
36 Bytes
Binary file not shown.
Binary file not shown.
36 Bytes
Binary file not shown.
Binary file not shown.

test/reference/html-x-y.pdf

34 Bytes
Binary file not shown.

test/saucelabs/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const browsers = {
1515
base: "SauceLabs",
1616
browserName: "chrome",
1717
platform: "Windows 10",
18-
version: "83"
18+
version: "94"
1919
},
2020
sl_firefox: {
2121
base: "SauceLabs",

test/specs/html.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ describe("Module: html", () => {
277277
});
278278

279279
it("page break with image", async () => {
280-
const doc = jsPDF({ floatPrecision: 2, unit: "pt", format: [100, 100] });
280+
const doc = jsPDF({ floatPrecision: 2, unit: "pt", format: [100, 100], lineWidth: 1 });
281281
await new Promise(resolve =>
282282
doc.html(
283283
'<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==" width="10" height="200">',
@@ -315,6 +315,14 @@ describe("Module: html", () => {
315315
comparePdf(doc.output(), "html-x-y.pdf", "html");
316316
});
317317

318+
it("is able to render html multiple times", async () => {
319+
const doc = jsPDF({ floatPrecision: 2, unit: "pt" });
320+
await doc.html("<div style='background: red; width: 10px; height: 10px;'></div>", { x: 30, y: 10 });
321+
await doc.html("<div style='background: red; width: 10px; height: 10px;'></div>", { x: 50, y: 10 });
322+
await doc.html("<div style='background: red; width: 10px; height: 10px;'></div>", { x: 10, y: 10 });
323+
comparePdf(doc.output(), "html-multiple.pdf", "html");
324+
});
325+
318326
it("html x, y + margin offsets properly", async () => {
319327
const doc = jsPDF({ floatPrecision: 2, unit: "pt" });
320328
doc.line(30, 10, 100, 10);

0 commit comments

Comments
 (0)