Skip to content
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

Experimental: Support PDF rendering #487

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/browser/browser.ts
Expand Up @@ -364,8 +364,9 @@
this.log.error('Error while waiting for the panels to load', 'url', options.url, 'err', err.stack);
}

const isPDF = options.encoding === 'pdf';
if (!options.filePath) {
options.filePath = uniqueFilename(os.tmpdir()) + '.png';
options.filePath = uniqueFilename(os.tmpdir()) + (isPDF ? '.pdf' : '.png');
}

await this.setPageZoomLevel(page, this.config.pageZoomLevel);
Expand All @@ -381,10 +382,21 @@
height: scrollResult.scrollHeight,
});
}

if (isPDF) {
return page.pdf({
path: options.filePath,
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
landscape: false,
format: 'Letter',
omitBackground: true,
printBackground: true, // ??
})
}

return page.screenshot({ path: options.filePath, fullPage: options.fullPageImage, captureBeyondViewport: options.fullPageImage || false });
Copy link
Member

Choose a reason for hiding this comment

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

should we wrap this in if(!isPDF ) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

not necessary given the if(isPDF) ... case returns, but perhaps an else clause would be cleaner (I don't have any strong opinions here)

Copy link
Member

Choose a reason for hiding this comment

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

ah, I missed the return. na early return is better than if/else :)

}, 'screenshot');

if (options.scaleImage) {
if (options.scaleImage && !isPDF) {
const scaled = `${options.filePath}_${Date.now()}_scaled.png`;
const w = +options.width / options.scaleImage;
const h = +options.height / options.scaleImage;
Expand Down