Skip to content

Commit 81f340b

Browse files
committed
Adjust pdf size
1 parent c8c2fdb commit 81f340b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

api/utils/pdf.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ exports.renderPDF = async function(html, callback, options = null, puppeteerArgs
7474
await page.setContent(html);
7575
}
7676

77+
const contentHeight = await page.evaluate(() => {
78+
/*global document*/
79+
return document.body.scrollHeight;
80+
});
81+
82+
options.width = '210mm'; // A4 width, for example
83+
options.height = `${contentHeight}px`; // full content height
84+
options.printBackground = true;
85+
options.preferCSSPageSize = true;
86+
7787
await page.pdf(options).then(callback, function(error) {
7888
log.d('pdf generation error', error);
7989
});

0 commit comments

Comments
 (0)