opengovsg / pdf2md

A PDF to Markdown converter
https://www.npmjs.com/package/@opendocsg/pdf2md
MIT License
195 stars 39 forks source link

Parsing PDF as MD fails in production in Nextjs 14 #80

Open danybeltran opened 8 months ago

danybeltran commented 8 months ago

Parsing PDF as MD fails in production in Nextjs 14

Parsing a pdf file as MD works fine in development, but fails in production, showing this error:

image

This is my typescript code:

async function getPDFContext(file: File) {
  if (file) {
    const pdf2md = require("@opendocsg/pdf2md")

    const pdfBuffer = await file.arrayBuffer()

    const pdfContent = await pdf2md(pdfBuffer)

    return pdfContent
  } else {
    return null
  }
}

To Reproduce In a Next.js app:

  1. Create a file input
  2. Open a pdf and parse it (should work)
  3. Build with npm run build
  4. Repeat step 2 (it fails)

Desktop: