fix(pdf): drop clipped and off-page text - #89
Merged
Merged
Conversation
Honor CropBox/MediaBox and W/W* clips so leftover next-page content in the stream is not emitted as markdown. fixes #79
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
mdgate-demo | bb53d1e | Aug 27 2026, 07:20 AM |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Appearance clip mixes coordinate spaces
- On-page appearances are kept by filtering on the annotation Rect in page space, and form streams are extracted without intersecting the form-space BBox with the page crop.
You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit cc80126. Configure here.
There was a problem hiding this comment.
Stale comment
Left a non-blocking comment. Cursor Bugbot finished as skipped and reported 1 unresolved issue, so this is not approved. Human review is needed; no reviewers were assigned because no eligible non-author reviewer is available.
Sent by Cursor Approval Agent: Pull Request Router and Approver
Appearance forms stay in form space. Intersecting their BBox with the page crop dropped on-page widgets and leaked off-page ones. Filter by the annotation Rect instead, then extract the form without a page clip.
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.



Summary
Confirmed #79. The three cited one-page crops keep the next page's text in the content stream. Viewers and
pdftotext -layouthide it with crop/clip. mdgate read the whole stream.On
01030000000027.pdfthat leaked6.Conclusion, the following essay, and49. On01030000000028.pdfand01030000000029.pdfeach file mixed in the adjacent page, so the two markdown outputs overlapped.CropBox equals MediaBox on these files. The leftover sits behind nested
re W nclips (and, on the right-hand crop, at negative x). The extractor ignored both.Changes
/Pages.W/W*clip rects, saved and restored withq/Q.Test plan
bunx vitest run packages/pdf/test(images included afterbun run build)bun run lintbun test(557 pass)Note
Medium Risk
Changes core content-stream interpretation and can drop previously extracted text if clip heuristics (axis-aligned path bounds) disagree with a viewer; scope is limited to the PDF package with targeted tests.
Overview
Fixes PDF-to-markdown leaking text that viewers hide via CropBox/MediaBox and content-stream clip paths (issue #79: adjacent-page content in cropped one-page exports).
The extractor now tracks a visible clip per page: CropBox (else MediaBox, including inheritance from
/Pages), intersected withW/W*path bounding boxes and saved/restored onq/Q. Text runs, stroke lines, filled rects, form XObject content (intersected with BBox), and annotation items are omitted when they do not overlap the active clip; annotation appearances are skipped when/Rectis off-page, while in-page widget labels still render.Adds
packages/pdf/test/clip.test.tscovering MediaBox/CropBox, nested clips, form BBox, and annotation edge cases.Reviewed by Cursor Bugbot for commit bb53d1e. Bugbot is set up for automated code reviews on this repo. Configure here.