Skip to content

fix(save): a snippet or vector print of an empty page no longer fails - #526

Merged
DutchSailor merged 1 commit into
mainfrom
fix/snippet-blank-page
Oct 6, 2026
Merged

DutchSailor merged 1 commit into
mainfrom
fix/snippet-blank-page

Conversation

@DutchSailor

Copy link
Copy Markdown
Collaborator

What happened

A page that pdf-lib created itself (a new document, or an inserted blank page) has no /Contents. pdf-lib throws "Can't embed page with missing Contents" when such a page is embedded, but only once the document is saved. So:

  • cutting a vector snippet from such a page made every later save of the document fail, not only that one;
  • printing a document with such a page in vector mode failed.

What this changes

  • New metInhoud(page) in js/pdf/vector-embed.js: gives a page without /Contents an empty content stream before embedding (only when it is missing, so existing content is never touched). The image does not change.
  • Used in bedKnipselIn (vector snippets) and in bouwVectorPrintPdf (vector print).

Verification

  • vector-embed.test.mjs: a snippet of a page without contents, opaque and translucent, saves twice. print-vector.test.mjs: a two-page document whose second page has no contents prints. Both tests failed first with exactly "Can't embed page with missing Contents".
  • npm run test:unit 2593 passed, 0 failed; npx vite build and npm run typecheck green.

Found by the review of #510; the bug exists on main and on #510 independently.

🤖 Generated with Claude Code

A page that pdf-lib created itself (new document, inserted blank page)
has no /Contents. pdf-lib throws on embedding such a page only when the
document is saved, so a vector snippet cut from it made every later save
of the document fail, and printing a document with such a page failed
in vector mode. Give the page an empty content stream before embedding;
the image does not change.
@DutchSailor
DutchSailor merged commit fff2147 into main Oct 6, 2026
4 checks passed
DutchSailor added a commit that referenced this pull request Oct 6, 2026
@DutchSailor
DutchSailor deleted the fix/snippet-blank-page branch October 6, 2026 06:38
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