Skip to content

fix(pdf): 伪空格切碎修复 + 扫描件 PDF_NO_TEXT_RUNS 警告 - #224

Merged
Vantalens merged 3 commits into
mainfrom
fix/pdf-fake-spaces
Sep 24, 2026
Merged

Vantalens merged 3 commits into
mainfrom
fix/pdf-fake-spaces

Conversation

@Vantalens

Copy link
Copy Markdown
Owner

概述

两个 PDF 文本抽取修复:

  1. 3c91124 fix: stop fake spaces from shredding letter-spaced PDF text(已有提交)——收拢 PDF 中的伪空格,修复加字距拉丁文本被切碎的问题
  2. 8d94243 fix(pdf): distinguish scanned PDFs with PDF_NO_TEXT_RUNS warning——pdf.js 成功解析页面但零文本 run 时(典型扫描件/图片型 PDF),不再落入笼统的 PDF_NO_CREDIBLE_TEXT("二进制噪声"文案对扫描件是误导),改为:
    • 新增 pdfJsParsedButTextless 判定
    • 发出 PDF_NO_TEXT_RUNS warning(severity: unsupported),details 携带 { pageCount, pagesWithoutText, ocrRecommended: true }
    • metadata.pdf.extraction 标记为 "pdfjs-no-text",pagesWithoutText 填入全部页号(顺带修正全扫描件 OCR 部分失败时 unresolvedPdfPages 漏报)
    • 加密 / GID 乱码 / 二进制噪声三条原有路径行为不变

验证

  • 样本 PDF(mixed-cn-en-form / spacing-stress / pdf-small)抽取全部正常,文本型路径无回归
  • 真实扫描件作业 PDF(2 页无文本层):警告正确触发;转换链路走本地 OCR 成功产出文本
  • ✅ pdf-reader-test(13 组)/ layout-offset-regression-test / smoke-test(60 组)/ conversion-quality-test(11 ok)/ format-integrity-test / ocr-baseline-test / ocr-readback-test / ui-conversion-e2e-test

关联

UI 侧对 PDF_NO_TEXT_RUNS 的展示接线在 #223 的 app.js 中(缺本分支时优雅降级为原通用提示)。

…view gradient buttons

Landing:
- bump hero eyebrow v2.3 -> v2.4 to match package version
- tighten hero vertical rhythm; split subtitle into nowrap phrases to
  drop the single-character orphan line
- gate .reveal-on-scroll behind a .reveal-armed class so content stays
  visible when JS/observer/print contexts never trigger intersection
- hover feedback for feature cards, format rows, workflow steps; CTA
  section gets a brand gradient bar

Workbench (styles.css only):
- dashed centered empty states, tab active indicator, focus-visible rings
- gradient progress bar with tabular-nums percentage
- stronger pane elevation, press feedback on ghost/mini/menu buttons

Preview (preview.css):
- explicit brand-gradient primary button rules for dark topbar context
  (fixes unified-button-test baseline failure: token now used 3x)

Chore: add npm run dev script alongside existing start script

Tests: design-token, ui-accessibility, ui-button-consistency (12/12),
unified-button, smoke (60 groups), browser-smoke, ui-conversion-e2e,
server-hardening all pass.
- item 拼接层空格阈值从 0.12em 提到 0.22em(近似真实空格宽度 0.25em),加字距
  排版字形间隙不再被当成词间空格("E x p a n d e d" 式碎词)
- pdf.js addFakeSpaces 伪空格的收拢:连续 ≥3 个单字 CJK 链去空格("加 字 距 版"
  →"加字距版"),多字词间对齐空格保留;拉丁碎词词边界在 pdf.js 合并 item 时已
  丢失,保留原样并注明上游限制
- 回归断言:加字距字形链不拆词、CJK 伪空格收拢、多字词空格保留

Refs #216
When pdf.js parses pages successfully but extracts zero text runs, the
document is almost certainly a scanned/image-only PDF. Previously this
fell into the generic PDF_NO_CREDIBLE_TEXT path, misleading users into
thinking the file was unreadable binary noise.

- add pdfJsParsedButTextless detection in readPdf fallback branch
- emit PDF_NO_TEXT_RUNS (severity: unsupported) with pageCount,
  pagesWithoutText and ocrRecommended: true in details
- mark metadata.pdf.extraction as "pdfjs-no-text" and fill
  pagesWithoutText with all page numbers (also fixes unresolvedPdfPages
  under-reporting when OCR partially fails on full-scan documents)
- encrypted / GID-noise / binary-noise paths unchanged

Verified with real-world scanned homework PDF (2 pages, no text layer):
warning fires correctly and OCR conversion produces usable text.
@Vantalens
Vantalens merged commit db1448e into main Sep 24, 2026
8 checks passed
@Vantalens
Vantalens deleted the fix/pdf-fake-spaces branch September 24, 2026 10:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d942437b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread public/formats/pdf.js
Comment on lines +442 to +444
export function collapseCjkFakeSpaces(text) {
const run = new RegExp(`(?:[${CJK_CHAR_CLASS}] ){2,}[${CJK_CHAR_CLASS}]`, "g");
return String(text).replace(run, (match) => match.replaceAll(" ", ""));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve intentional spaces in CJK text runs

collapseCjkFakeSpaces is applied to every PDF.js text item, but item.str can contain literal spaces from the document as well as spaces synthesized by PDF.js. Consequently, intentionally spaced content such as 我 爱 中 国 or spaced names/headings is silently rewritten to 我爱中国 during every PDF-to-text conversion. The collapse needs evidence that the spaces were synthesized (for example, glyph-position/width analysis) rather than treating every run of three single CJK characters as fake spacing.

Useful? React with 👍 / 👎.

Vantalens added a commit that referenced this pull request Sep 24, 2026
Resolve conflicts from squash-merged #221 (identical content to this
branch's first commit) and #224 (pdf.js scanned-PDF warning): take the
redesigned UI files; pdf.js and docs come from main unchanged.
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