Skip to content

Commit

Permalink
Added custom height
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Jul 18, 2023
1 parent c49e1f1 commit 5f916b9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/commands/GeneratePDF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import Command from "./Command";

let document: any;

function getMaxHeight() {
return Array.from<any>(document.all).reduce((a, c) => Math.max(c.scrollHeight , a) , 0);
function updatePageSize() {
const maxHeight = Array.from<any>(document.all).reduce((a, c) => Math.max(c.scrollHeight , a) , 0);
document.body.style.height = `${maxHeight}px`;
document.body.style.overflow = "auto";
}

export default class GeneratePDF extends Command {
async render({ outputFile: path, page, output, pdf }: IEvent) {

// find div with maximum scroll height
const maxHeight = await page.evaluate(getMaxHeight);
await page.evaluate(updatePageSize);

const pf = typeof pdf === "object"
? { ... pdf, path}
: { path };

pf.format ??= "A4";
pf.height = maxHeight + "px";

await page.pdf(pf);

Expand Down

0 comments on commit 5f916b9

Please sign in to comment.