Skip to content

Commit

Permalink
Enable PNG image transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Oct 21, 2023
1 parent 49daf69 commit cb4c1ec
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ export class Converter {
await render()
await page.emulateMediaType('print')

if (opts.type === ConvertType.png) {
// Enable transparency
await page.addStyleTag({
content: ':root,body { background:transparent !important; }',
})
}

const screenshot = async (pageNumber = 1) => {
const clip = {
x: 0,
Expand All @@ -406,7 +413,11 @@ export class Converter {
type: 'jpeg',
})

return await page.screenshot({ clip, type: 'png' })
return await page.screenshot({
clip,
omitBackground: true,
type: 'png',
})
}

if (opts.pages) {
Expand Down

0 comments on commit cb4c1ec

Please sign in to comment.