question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'compressed' of undefined

See original GitHub issue

We ran into a pdfjs (v2.4.5) problem: https://github.com/nbesli/pdf-merger-js/issues/42

The following code-snipped…

const doc = new pdf.Document()
const src = await fs.readFile(path.join(FIXTURES_DIR, 'issue-42.pdf'))
const ext = new pdf.ExternalDocument(src)
doc.addPagesOf(ext)
const fileBuffer = await doc.asBuffer()
await fs.writeFile(path.join(TMP_DIR, 'Testfile_issue-42.pdf'), fileBuffer)

…results in this error:

TypeError: Cannot read property 'compressed' of undefined

      at parseObject (node_modules/pdfjs/lib/object/reference.js:81:15)
      at PDFReference.get [as object] (node_modules/pdfjs/lib/object/reference.js:15:17)
      at Function.addObjectsRecursive (node_modules/pdfjs/lib/parser/parser.js:68:35)
      at Function.addObjectsRecursive (node_modules/pdfjs/lib/parser/parser.js:84:18)
      at Function.addObjectsRecursive (node_modules/pdfjs/lib/parser/parser.js:75:16)
      at ExternalDocument.write (node_modules/pdfjs/lib/external.js:62:14)

Please find the problematic PDF file attached: issue-42.pdf

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
rkusacommented, Aug 18, 2021

Thanks for the report! I looked into it and the cause of the issue seems to be that pdfjs does not support hybrid-reference files. More specifically, the support for the XRefStm property of the trailer is not yet implemented. While it successfully falls back to the normale xref table (instead of the xref stream), the normal xref table is missing the object with the ID 46, which is thus unknown and causes the error you’ve posted.

Possible solutions:

  • Implement support for XRefStm
  • Silently ignore missing objects (I am not sure if I’d like this solution though)

I don’t have the time right now to implement it, but I’ll keep it in the back of my mind.

6reactions
necropolinacommented, Oct 5, 2021

Any suggested temporary fixes that we might be able to use to circumvent this error while the issue is waiting to be resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

pdf-merger-js throws a TypeError and Fails - Stack Overflow
Uncaught TypeError : Cannot read property 'compressed' of undefined. and the merger would fail. I tried different versions of node with the ...
Read more >
Examples
This tutorial shows how PDF.js can be used as a library in a web browser. examples/ provides more examples, including usage in Node.js...
Read more >
Error loading PDF (Cannot read properties of undefined ...
Hi,. I'm trying the PDF Viewer to see if it suits the needs of our company and trying various PDFs, I have encountered...
Read more >
Uncaught TypeError: Cannot read property 'messages' of ...
The error happens when the library `cv.jquery.validate` is added by BigPipe and compressed. I just disabled the library compressing in ...
Read more >
split and merge pdf pages [36753526] - Issue Tracker - Google
TypeError : Cannot read property "0" from null. (line 50, file "Code") ... I believe it is in some type of compressed data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found