How to use the pdf-lib.PDFDocument.load function in pdf-lib

To help you get started, we’ve selected a few pdf-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Mogztter / asciidoctor-pdf.js / lib / converter.js View on Github external
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 => {})