Skip to content

Commit

Permalink
support pdf rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed Dec 17, 2023
1 parent 8563719 commit fcb6f0e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ export class Browser {
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 @@ export class Browser {
height: scrollResult.scrollHeight,
});
}

if (isPDF) {
return page.pdf({
path: options.filePath,

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 });
}, '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

0 comments on commit fcb6f0e

Please sign in to comment.