Skip to content

Commit 92aeb07

Browse files
committed
Improve PDF
1 parent 3edaa4e commit 92aeb07

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

index.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,42 @@ module.exports = launchOpts => {
6060

6161
const pdf = async (url, opts = {}) => {
6262
const tempFile = createTempFile({ ext: `.pdf` })
63-
const { media = 'screen' } = opts
6463
const { path } = tempFile
6564

65+
const {
66+
media = 'screen',
67+
format = 'A4',
68+
printBackground = true,
69+
waitUntil = 'networkidle',
70+
viewport = {
71+
width: 2560,
72+
height: 1440
73+
},
74+
margin = {
75+
top: '0.25cm',
76+
right: '0.25cm',
77+
bottom: '0.25cm',
78+
left: '0.25cm'
79+
}
80+
} = opts
81+
6682
const page = await newPage()
67-
await page.goto(url, { waitUntil: 'networkidle' })
83+
await page.setViewport(viewport)
84+
await page.goto(url, { waitUntil })
6885
await page.emulateMedia(media)
69-
await page.pdf(Object.assign({ path }, opts))
86+
87+
await page.pdf(
88+
Object.assign(
89+
{
90+
margin,
91+
path,
92+
format,
93+
printBackground
94+
},
95+
opts
96+
)
97+
)
98+
7099
page.close()
71100

72101
return Promise.resolve(tempFile)

0 commit comments

Comments
 (0)