Skip to content

fix(pdf): reliably extract PDF images across browsers - #216

Merged
slaveofcode merged 1 commit into
developfrom
fix/extract-images-legacy-pdfjs
Aug 14, 2026
Merged

fix(pdf): reliably extract PDF images across browsers#216
slaveofcode merged 1 commit into
developfrom
fix/extract-images-legacy-pdfjs

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

Follow-up to the extract-images fix. Two real bugs found via headless-browser reproduction of a user's PDF:

  1. a.toHex is not a function — pdf.js's default build uses Uint8Array.prototype.toHex, absent on many browsers. Switched Extract-Images to the pdf.js legacy build (polyfilled).
  2. 0 images even after decode — pdf.js image objects are ImageBitmaps whose dimensions live on obj.width/height, not on the bitmap; my code read obj.bitmap.width (undefined) → 0×0 canvas → null. Now draws with obj.width/height.

Verified end-to-end with Playwright against a local build: the user's sample PDF now extracts all 5 embedded images.

- Use pdf.js legacy build (polyfills Uint8Array.toHex etc.) so extraction
  no longer crashes on browsers without the newest JS.
- Draw the decoded image using its own width/height (pdf.js stores the
  bitmap dimensions there, not on the bitmap), so ImageBitmap objects now
  encode correctly instead of producing a 0-size canvas.

Verified end-to-end in a headless browser: a sample PDF now yields all its
embedded images instead of 'no images found'.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
goodwebtools b59cf9c Aug 14 2026, 04:16 AM

@slaveofcode
slaveofcode merged commit 929fb7f into develop Aug 14, 2026
2 checks passed
@slaveofcode
slaveofcode deleted the fix/extract-images-legacy-pdfjs branch August 14, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant