Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 14 additions & 12 deletions src/modules/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,12 @@ import { globalObject } from "../libs/globalObject.js";
position: "relative",
display: "inline-block",
width:
Math.max(
this.prop.src.clientWidth,
this.prop.src.scrollWidth,
this.prop.src.offsetWidth
) + "px",
(this.opt.html2canvas.width ||
Math.max(
this.prop.src.clientWidth,
this.prop.src.scrollWidth,
this.prop.src.offsetWidth
)) + "px",
left: 0,
right: 0,
top: 0,
Expand All @@ -339,13 +340,14 @@ import { globalObject } from "../libs/globalObject.js";

if (source.tagName === "BODY") {
containerCSS.height =
Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.documentElement.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight
) + "px";
(this.opt.html2canvas.height ||
Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.documentElement.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight
)) + "px";
}

this.prop.overlay = createElement("div", {
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 added test/reference/html-width-100.pdf
Binary file not shown.
Binary file added test/reference/html-width-210.pdf
Binary file not shown.
Binary file added test/reference/html-width-300.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion test/specs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If a reference PDF doesn't exist it will be created if you run this command
while the tests run:

```
node tests/utils/reference-server.js
node test/utils/reference-server.js
```

This generates and collects reference PDFs from real browsers. This should be
Expand Down
23 changes: 22 additions & 1 deletion test/specs/html.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function toFontFaceRule(fontFace) {
`;
}

describe("Module: html", function() {
describe("Module: html", () => {
if (
(typeof isNode != "undefined" && isNode) ||
navigator.userAgent.indexOf("Chrome") < 0
Expand All @@ -41,6 +41,27 @@ describe("Module: html", function() {
comparePdf(doc.output(), "html-basic.pdf", "html");
});

it("html respects the width option", async () => {
const markup = "<div>" +
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet reprehenderit nihil natus magnam doloremque voluptate ab, laborum officiis corrupti eius voluptatibus quisquam illum esse corporis quod fugit quibusdam minima provident." +
"</div>";

// Full page size
const doc210 = await render(markup,
{ html2canvas: { width: 210 } });
comparePdf(doc210.output(), "html-width-210.pdf", "html");

// Wider than page
const doc300 = await render(markup,
{ html2canvas: { width: 300 } });
comparePdf(doc300.output(), "html-width-300.pdf", "html");

// Smaller than page
const doc100 = await render(markup,
{ html2canvas: { width: 100 } });
comparePdf(doc100.output(), "html-width-100.pdf", "html");
});

it("renders font-faces", async () => {
const opts = {
fontFaces: [
Expand Down