Skip to content

🐛 Rebuild PDF paragraph copy text and improve chapter headings - #4

Merged
JFWooten4 merged 3 commits into
mainfrom
bella-brella
Oct 15, 2026
Merged

JFWooten4 merged 3 commits into
mainfrom
bella-brella

Conversation

@codex-pony

@codex-pony codex-pony Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Retag an existing PDF's text structure without rerunning OCR or rasterizing its pages. The new --retag option reconstructs paragraph /ActualText while 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.md documents the new command:

python3 tag-ocr-pdf.py TAGGED.pdf RETAGGED.pdf --retag

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: /ActualText provides 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.

JFWooten4 and others added 3 commits October 12, 2026 08:49
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>
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