Skip to content

Fix not rendering multiple calls to html() #3271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions src/modules/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,12 @@ import { globalObject } from "../libs/globalObject.js";
)
: options.windowHeight;

pdf.context2d.save(true);
return html2canvas(this.prop.container, options);
})
.then(function toContext2d_post(canvas) {
this.opt.jsPDF.context2d.restore(true);

// Handle old-fashioned 'onrendered' argument.
var onRendered = this.opt.html2canvas.onrendered || function() {};
onRendered(canvas);
Expand Down
Binary file modified test/reference/html-basic.pdf
Binary file not shown.
Binary file modified test/reference/html-font-faces.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-page-break-image.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-page-break-slice.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-page-break-text.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-page-break.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-x-y-text.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-x-y.pdf
Binary file not shown.
Binary file modified test/reference/html-margin.pdf
Binary file not shown.
Binary file added test/reference/html-multiple.pdf
Binary file not shown.
Binary file modified test/reference/html-width-100-windowWidth-500.pdf
Binary file not shown.
Binary file modified test/reference/html-width-210-windowWidth-1000.pdf
Binary file not shown.
Binary file modified test/reference/html-width-210-windowWidth-250.pdf
Binary file not shown.
Binary file modified test/reference/html-width-210-windowWidth-500.pdf
Binary file not shown.
Binary file modified test/reference/html-width-300-windowWidth-500-scale-2.pdf
Binary file not shown.
Binary file modified test/reference/html-width-300-windowWidth-500.pdf
Binary file not shown.
Binary file modified test/reference/html-width-default-windowWidth-default.pdf
Binary file not shown.
Binary file modified test/reference/html-x-y.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion test/saucelabs/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const browsers = {
base: "SauceLabs",
browserName: "chrome",
platform: "Windows 10",
version: "83"
version: "94"
},
sl_firefox: {
base: "SauceLabs",
Expand Down
8 changes: 8 additions & 0 deletions test/specs/html.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ describe("Module: html", () => {
comparePdf(doc.output(), "html-x-y.pdf", "html");
});

it("is able to render html multiple times", async () => {
const doc = jsPDF({ floatPrecision: 2, unit: "pt" });
await doc.html("<div style='background: red; width: 10px; height: 10px;'></div>", { x: 30, y: 10 });
await doc.html("<div style='background: red; width: 10px; height: 10px;'></div>", { x: 50, y: 10 });
await doc.html("<div style='background: red; width: 10px; height: 10px;'></div>", { x: 10, y: 10 });
comparePdf(doc.output(), "html-multiple.pdf", "html");
});

it("html x, y + margin offsets properly", async () => {
const doc = jsPDF({ floatPrecision: 2, unit: "pt" });
doc.line(30, 10, 100, 10);
Expand Down