Repository navigation
fix: Content returns the text of form XObjects - #97
Open
anaelorlinski wants to merge 2 commits into
Open
anaelorlinski wants to merge 2 commits into
anaelorlinski wants to merge 2 commits into
Conversation
Content had no case for the Do operator, so the text drawn inside a form XObject (form-field appearances, embedded diagrams, headers placed as forms) was missing from the page. Do now interprets a form XObject's content stream in a saved graphics state, with the form's /Matrix concatenated to the CTM and the form's own /Resources (or, without them, those of the content stream painting it; PDF 32000-1:2008 §8.10). Image XObjects are ignored as before. Nesting is bounded by maxFormDepth since a form can paint itself. Refs ledongthuc#67
kvii
reviewed
Oct 28, 2026
| // } | ||
| return | ||
|
|
||
| case "Do": // paint an XObject; the text drawn by a form XObject is part of the page |
There was a problem hiding this comment.
Some time users want to read text in XObject directly. So I think it's better to define XObject as a seperate struct, like pdf.Page.
Address review on ledongthuc#97: users sometimes want to read the text inside an XObject directly, not only as a side effect of rendering the page. Add an exported XObject type that mirrors Page: Page.XObjects / Page.XObject reach a page's XObjects by name, XObject.XObjects / XObject.XObject reach nested ones, XObject.IsForm reports whether it is a form, and XObject.Content interprets a form's content stream (with its /Matrix applied) to return the text and rectangles it draws. Content's form handling is factored into a shared interpretContentStream helper so Page.Content and XObject.Content run the same interpreter. The Do operator recurses through it, keeping the existing behaviour: a form paints in a saved graphics state with its /Matrix concatenated to the CTM, a form without /Resources uses those of the painting stream, image XObjects add no text, and nesting is bounded by maxFormDepth.
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.
Content() had no case for Do, so text drawn inside a form XObject (form-field appearances, embedded diagrams, headers placed as forms) was missing. Do now interprets a form's content stream in a saved graphics state, with the form's /Matrix concatenated to the CTM and its own /Resources (or those of the painting stream; PDF 32000-1:2008 §8.10). Image XObjects are ignored as before; nesting is bounded by maxFormDepth since a form can paint itself.
Refs #67 (which covers GetPlainText; this is the Content() side). Tests build small PDFs in memory, like buildContentPDF.