Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.6k stars 635 forks source link

Failed to parse PDF document (line:104 col:8 offset=195965): No PDF header found #1646

Open pradeepgp0 opened 1 month ago

pradeepgp0 commented 1 month ago

What were you trying to do?

I need to read the pdf file which is present in react repo root directory which is under public folder, "sample.pdf"

How did you attempt to do it?

const formUrl = '/sample.pdf'; const formPdfBytes = await fetch(formUrl).then(res => res.arrayBuffer()); const pdfBufferData = await PDFDocument.load(formPdfBytes); console.log('arrayBuffer', formPdfBytes.byteLength); console.log('pdfBuffer', pdfBufferData);

What actually happened?

I am getting the below exception, the arrayBufffer

Failed to parse PDF document (line:104 col:8 offset=195965): No PDF header found

What did you expect to happen?

It should load the PDFDocument.load(pdfBytes)

How can we reproduce the issue?

By running the above code in react project .js file,,,,,,

Version

^1.17.1

What environment are you running pdf-lib in?

Browser, Other

Checklist

Additional Notes

nothing