Skip to main content

A PDF to HTML converter focused on layout preservation and table extraction.

Project description

PDF to HTML Engine

一个高性能、高保真度的 PDF 转 HTML 引擎,专注于 精准布局还原复杂表格提取 以及 跨页表格无缝处理。它针对复杂报表和布局进行了深度优化,能够满足各种高要求的 PDF 转换场景。

🚀 核心功能

  • 高保真布局还原:基于原子级坐标分析,通过 padding 和动态字体计算,精确还原文本的视觉位置。
  • 智能表格解析:利用几何分析能力,完美支持复杂单元格合并(rowspan/colspan)及文本对齐。
  • 跨页表格合并:独有的跨页逻辑,可识别并自动合并跨页断裂的表格,支持自动剔除重复表头。
  • 双阶段扫描 (Two-Pass):通过预扫描统一全局表格网格坐标,解决 PDF 转换中常见的列对齐微差问题。
  • 智能下划线识别:自动关联文本与其下方的图形线条,将填空下划线还原为语义化的 HTML 标签。

🛠️ 安装

pip install pdf2html-engine

📖 快速上手

1. 作为 Python 库使用

from pdf2html_engine import parse_pdf

# 简单转换
html_content = parse_pdf("sample.pdf")

# 或者使用 PDFConverter 进行精细控制
from pdf2html_engine import PDFConverter

converter = PDFConverter("sample.pdf")
# pages: 指定页码(例如 [1, 2, 3])
# full_html: 是否包含完整的 HTML 文档结构(html, body, head 等)
html = converter.convert(pages=[1, 2], full_html=True)

with open("output.html", "w", encoding="utf-8") as f:
    f.write(html)

2. 命令行工具 (CLI)

安装后,你可以直接在终端使用 pdf2html 命令:

# 基本转换
pdf2html input.pdf -o output.html

# 转换指定页码
pdf2html input.pdf -o output.html --pages 1-5,10

CLI 参数说明:

  • input_pdf: 输入的 PDF 文件路径。
  • -o, --output: 输出的 HTML 文件路径(默认为 output.html)。
  • -p, --pages: 指定转换的页码(例如 1,2,31-5)。

🧠 核心架构原理

  1. 视觉行聚类 (Visual Line Grouping):按 Y 轴坐标对字符进行聚类,容忍微小垂直偏移,实现“所见即所得”的行合并。
  2. 网格统一 (Grid Unification):在 Pass 1 阶段收集所有页面的表格坐标,Pass 2 强制使用统一网格,确保跨页表格视觉对齐。
  3. 图形关联:扫描 PDF 的 drawings 层,将线条与文本位置匹配,智能判定下划线语义。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf2html_engine-1.0.7.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf2html_engine-1.0.7-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file pdf2html_engine-1.0.7.tar.gz.

File metadata

  • Download URL: pdf2html_engine-1.0.7.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pdf2html_engine-1.0.7.tar.gz
Algorithm Hash digest
SHA256 265e3d2f9dc135fe26a131535aade910563131721d62360895716fd4f54ddfa1
MD5 f8664087e4d8764664f4dc850a58ce95
BLAKE2b-256 c2b644859d0f55fc1ae46c6049ffdd9ae1532c250d06ea6872ae149fcc1d3f37

See more details on using hashes here.

File details

Details for the file pdf2html_engine-1.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for pdf2html_engine-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0c880634e47580ef62da25a5574958c73f5152d9855fc9dfa38fbefd09415d72
MD5 36e359de7eb0fc31b302f5c7b3734152
BLAKE2b-256 fe32ad9638fd8f454054054e6ed23ec94f58bdd647b15cd8186b4968669a8a55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page