Repository navigation
fix(save): a snippet or vector print of an empty page no longer fails - #526
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:What this changes
metInhoud(page)injs/pdf/vector-embed.js: gives a page without/Contentsan empty content stream before embedding (only when it is missing, so existing content is never touched). The image does not change.bedKnipselIn(vector snippets) and inbouwVectorPrintPdf(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:unit2593 passed, 0 failed;npx vite buildandnpm run typecheckgreen.Found by the review of #510; the bug exists on
mainand on #510 independently.🤖 Generated with Claude Code