Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

366
Vistas
Load PDF document with PDF-LIB on Node gives "No PDF header found"

Im loading a PDF document I have to modify on the fly with PDF-lib.

const { PDFDocument } = require('pdf-lib');

The PDF file is built with Acrobat and its called dental_insurance.pdf.

I tried to load the file the following ways:

const pdfDoc = await PDFDocument.load("/documents/cards/dental_insurance.pdf")

const pdfDoc = await PDFDocument.load("C:/Website/test/desk_routes/documents/cards/dental_insurance.pdf")

const pdfDoc = await PDFDocument.load("./documents/cards/dental_insurance.pdf")

const pdfDoc = await PDFDocument.load("../documents/cards/dental_insurance.pdf")

But no matter how I set the route where the file is located, I get this error:

(node:15196) UnhandledPromiseRejectionWarning: Error: Failed to parse PDF document (line:4 col:2 offset=27): No PDF header found

I checked at PDF-lib documentation, they only state the following to load a file:

const pdfDoc = await PDFDocument.load("...")

I dont believe the problem is on the PDF file since I get the very same error even if I enter a file that doesn't exist:

const pdfDoc = await PDFDocument.load("blablabla.pdf")

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Per the documentation, PDFDocument.load() accepts a string which is the contents of the pdf file, not the name.

const fs = require('fs/promises');

const pdfData = await fs.readFile('./documents/cards/dental_insurance.pdf');

const pdfDoc = await PDFDocument.load(pdfData);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda