Skip to content

feat(pdf): add searchable PDF generation from OCR results - #33

Open
hnlyf168 wants to merge 2 commits into
sdcb:mainfrom
hnlyf168:feat/searchable-pdf
Open

hnlyf168 wants to merge 2 commits into
sdcb:mainfrom
hnlyf168:feat/searchable-pdf

Conversation

@hnlyf168

Copy link
Copy Markdown
Contributor

功能说明

新增 Sdcb.SimdPaddleOCR.Pdf 库与 SkiaSharp.SearchablePdf 示例,把页面图片 + OCR 结果生成为可搜索、可复制的双层 PDF:

  • PaddleOcrPdfWriter:轻量 PDF 1.4 写入器(页对象、xref、trailer),每页嵌入原始图片 + 依 OCR 行/字符框定位的透明文本层,支持任意 Stream 输出。
  • PdfTextAlignment:基于 CTC 的字符框估计与 padding emission 过滤,文本层与图像对齐。
  • PdfImage:SkiaSharp 解码为 BGRA,供 OCR 流水线使用。
  • 示例 SkiaSharp.SearchablePdf:目录图片 -> 单个多页 PDF 或每图一个 PDF(--separate),含分阶段计时、CPU/内存采样与 JSON/CSV 基准报告。

注:本分支基于 #32(feat/document-orientation),如该 PR 先合并,此处仅剩 PDF 相关提交。

使用示例

dotnet run -c Release --project examples/SkiaSharp.SearchablePdf -- <图片目录> <输出目录> --model medium --backend auto --dpi 300 --det-size 1600 --separate

验证

  • test/Sdcb.SimdPaddleOCR.Pdf.Tests:14 个测试全部通过(写入器结构、文本层、对齐过滤、round-trip 文本提取)。
  • 53 张整页扫描件(medium/1600,GPU auto)实测:单图全流程 308.6 ms(OCR 251 ms + 解码 53 ms + PDF 4 ms),约 3.2 张/s;PDF 生成仅占约 1.3%,非瓶颈。
模型/detSize 纯 OCR (ms/张) 行数
medium/1600 278.4 4928
medium/960 234.9 4619
tiny/1600 95.3 4832
tiny/960 81.9 4774

文档

🤖 由 Copilot 生成

sauceCruet and others added 2 commits October 13, 2026 16:52
Add Sdcb.SimdPaddleOCR.Pdf library that turns page images plus OCR
results into searchable, copyable dual-layer PDFs:

- PaddleOcrPdfWriter: minimal PDF 1.4 writer (pages, xref, trailer)
  embedding the original image per page with a transparent text layer
  positioned from OCR line/character boxes; works with any stream.
- PdfTextAlignment: CTC-based character box estimation plus padding
  emission filtering, so text layer placement follows the image.
- PdfImage: SkiaSharp decode into BGRA pixels for the OCR pipeline.
- Example SkiaSharp.SearchablePdf: folder of images -> one multi-page
  PDF or one PDF per image (--separate) with per-stage timing,
  CPU/memory sampling and JSON/CSV benchmark reports.
- Tests: 14 tests covering writer structure, text layer, alignment
  filtering and round-trip text extraction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

2 participants