Skip to content

Commit

Permalink
Fix print.pdf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Dec 11, 2023
1 parent 6eeb439 commit 9e369af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions print.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ const run = async () => {
// Switch to print mode and scroll to the bottom
// Ensures the PDF call knows the correct document height
await page.emulateMediaType('print');
await page.evaluate(() => {
window.scrollTo(0, document.body.scrollHeight);
});
await page.evaluate(() => new Promise(resolve => {
window.requestAnimationFrame(() => {
window.requestAnimationFrame(() => {
window.scrollTo(0, document.body.scrollHeight);
resolve();
});
});
}));

// Export the PDF and exit
await page.pdf({
preferCSSPageSize: true,
path: path.join(__dirname, 'build', 'print.pdf')
format: 'A4',
path: path.join(__dirname, 'build', 'print.pdf'),
displayHeaderFooter: true,
headerTemplate: '<div></div>',
footerTemplate: '<div style="font-size: 8px; font-family: \'Courier New\', monospace; width: 100%; text-align: center;">mattcowley.co.uk</div>'
});
await browser.close();
await server.close();
Expand Down
2 changes: 1 addition & 1 deletion scss/components/_print.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $brand: #0069ff;
@media print {
html,
body {
background: #fff;
background: transparent;
color: #000;
font-size: 10px;
height: auto;
Expand Down

0 comments on commit 9e369af

Please sign in to comment.