Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (pdfWidth) {
pdfOptions.width = pdfWidth
}
const pdfHeight = doc.getAttributes()['pdf-height']
if (pdfHeight) {
pdfOptions.height = pdfHeight
}
const format = doc.getAttributes()['pdf-format']
if (format) {
pdfOptions.format = format // Paper format. If set, takes priority over width or height options. Defaults to 'Letter'.
}
let pdf = await page.pdf(pdfOptions)
// Outline is not yet implemented in Chromium, so we add it manually here.
// https://bugs.chromium.org/p/chromium/issues/detail?id=840455
let pdfDoc = await PDFDocument.load(pdf)
pdfDoc = await addOutline(pdfDoc, doc)
pdfDoc = await addMetadata(pdfDoc, doc)
pdf = await pdfDoc.save()
if (outputToStdout) {
console.log(pdf.toString())
} else {
fsExtra.writeFileSync(outputFile, pdf)
}
}
} catch (err) {
console.log('Unable to generate the PDF - Error: ' + err.toString())
} finally {
if (watch || preview) {
if (!watch) {
console.log('Preview mode entered, needs to be manually terminated using Ctrl+C!')
await new Promise(resolve => {})