Repository navigation
🐛 Rebuild PDF paragraph copy text and improve chapter headings - #4
Merged
Merged
Conversation
Co-authored-by: Codex <noreply@openai.com>
Select extractable text instead of decorative Form objects. Add explicit retagging that preserves metadata, bookmarks, drawing instructions, and native hard hyphens while joining font runs into paragraph ActualText. Co-authored-by: Codex <noreply@openai.com>
Recognize explicit chapter labels with italic or distinctively sized titles, including additional numbering conventions. Keep bare numerals constrained to established bold heading styles and nearby, aligned title text; add positive and negative regressions. Co-authored-by: Codex Web <noreply@openai.com>
This was referenced Oct 16, 2026
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.
Retag an existing PDF's text structure without rerunning OCR or rasterizing its pages. The new
--retagoption reconstructs paragraph/ActualTextwhile leaving text and drawing operations intact, preserving existing bookmarks and document metadata instead of replacing them. It removes old structure markers but retains optional-content layer scopes; ordinary runs still leave existing tagged structure alone unless retagging is explicitly requested.Native-text extraction now selects pages or Form XObjects that actually contain extractable text, rather than mistaking decorative vector Forms for OCR layers. It rejoins adjacent font/style runs on a printed line, adds spacing where text-positioning operators indicate a break, and keeps printed hard hyphens when joining native lines. The existing OCR dehyphenation behavior remains distinct.
Chapter detection also combines separately printed labels and titles into one semantic heading and, when generating an outline, one bookmark. It supports numbered, Roman-numeral, word-numbered, abbreviated chapter, part, and appendix labels, including italic or larger titles. Proximity, alignment, capitalization, length, and typographic constraints limit accidental merges with ordinary prose.
Regression coverage includes repeated retagging, metadata and outline retention, unchanged non-tag drawing instructions, optional-content scopes, decorative Forms beside real text, native run joining and hyphenation, varied chapter styles, and negative cases for body text.
OCR.mddocuments the new command:The earlier AI-reviewed OCR and bookmark work established the structure-tagging pipeline that this change can now revisit without replacing an existing outline.
6eb36a4
The native-text work also builds on the existing TrueType WinAnsi extraction support.
13478e5
Viewer limitation:
/ActualTextprovides replacement text for extraction, but does not force every PDF viewer to copy paragraphs without printed line breaks. See the PDF Association's ActualText explanation and pikepdf's metadata-saving behavior.