Skip to content

Fix margin values not working for html #2977

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 23 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix html tests
  • Loading branch information
jeffsieu committed Oct 29, 2020
commit d2068505969fed1579980a8321b60c145f6c0eb7
6 changes: 3 additions & 3 deletions src/modules/context2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ import { console } from "../libs/console.js";

var topMargin = (i === min ? this.posY + this.margin[0] : this.margin[0]);
var firstPageHeight = this.pdf.internal.pageSize.height - this.posY - this.margin[0] - this.margin[2];
var pageHeightMinusMargin = this.pdf.internal.pageSize.height - this.margin[2];
var pageHeightMinusMargin = this.pdf.internal.pageSize.height - this.margin[0] - this.margin[2];
var pageWidthMinusMargin = this.pdf.internal.pageSize.width - this.margin[1];
var previousPageHeightSum = i === 1 ? 0 : firstPageHeight + (i - 2) * pageHeightMinusMargin;

Expand Down Expand Up @@ -1677,7 +1677,7 @@ import { console } from "../libs/console.js";

var topMargin = (k === min ? this.posY + this.margin[0] : this.margin[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 1 instead of min here as well.

Suggested change
var topMargin = (k === min ? this.posY + this.margin[0] : this.margin[0]);
var topMargin = (k === 1 ? this.posY + this.margin[0] : this.margin[0]);

var firstPageHeight = this.pdf.internal.pageSize.height - this.posY - this.margin[0] - this.margin[2];
var pageHeightMinusMargin = this.pdf.internal.pageSize.height - this.margin[2];
var pageHeightMinusMargin = this.pdf.internal.pageSize.height - this.margin[0] - this.margin[2];
var previousPageHeightSum = k === 1 ? 0 : firstPageHeight + (k - 2) * pageHeightMinusMargin;

if (this.ctx.clip_path.length !== 0) {
Expand Down Expand Up @@ -2042,7 +2042,7 @@ import { console } from "../libs/console.js";

var topMargin = (i === min ? this.posY + this.margin[0] : this.margin[0]);
var firstPageHeight = this.pdf.internal.pageSize.height - this.posY - this.margin[0] - this.margin[2];
var pageHeightMinusMargin = this.pdf.internal.pageSize.height - this.margin[2];
var pageHeightMinusMargin = this.pdf.internal.pageSize.height - this.margin[0] - this.margin[2];
var pageWidthMinusMargin = this.pdf.internal.pageSize.width - this.margin[1];
var previousPageHeightSum = i === 1 ? 0 : firstPageHeight + (i - 2) * pageHeightMinusMargin;

Expand Down
Binary file modified test/reference/html-basic.pdf
Binary file not shown.
Binary file modified test/reference/html-margin.pdf
Binary file not shown.
Binary file modified test/reference/html-x-y.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions test/specs/html.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe("Module: html", function() {
});

it("html margin insets properly", async () => {
const doc = jsPDF();
const doc = jsPDF({ floatPrecision: 2 });
await new Promise(resolve =>
doc.html("<h1>Basic HTML</h1><h2>Heading 2</h2>", { callback: resolve, margin: [10, 10] })
);
comparePdf(doc.output(), "html-margin.pdf", "html");
});

it("html x, y offsets properly", async () => {
const doc = jsPDF();
const doc = jsPDF({ floatPrecision: 2 });
await new Promise(resolve =>
doc.html("<h1>Basic HTML</h1><h2>Heading 2</h2>", { callback: resolve, x: 30, y: 40 })
);
Expand Down