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,3或1-5)。
🧠 核心架构原理
- 视觉行聚类 (Visual Line Grouping):按 Y 轴坐标对字符进行聚类,容忍微小垂直偏移,实现“所见即所得”的行合并。
- 网格统一 (Grid Unification):在 Pass 1 阶段收集所有页面的表格坐标,Pass 2 强制使用统一网格,确保跨页表格视觉对齐。
- 图形关联:扫描 PDF 的
drawings层,将线条与文本位置匹配,智能判定下划线语义。
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(21.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdf2html_engine-1.0.1.tar.gz.
File metadata
- Download URL: pdf2html_engine-1.0.1.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5c7d7266199af5c4e526ab9cf3da4b82eb921536f9246991b505a1053361006
|
|
| MD5 |
c9512644860395886958b4999a2635d4
|
|
| BLAKE2b-256 |
6eb3aa858b49943d30649ce17c331c3ae84b9dc83bb0fe289eddf77474eca151
|
File details
Details for the file pdf2html_engine-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pdf2html_engine-1.0.1-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e8ebfb84c33bcf267e2896ffcbf007b7cdefa0a6eff0b4390fb4863f53bd47c
|
|
| MD5 |
27551d579ad60609a9ced41d16021913
|
|
| BLAKE2b-256 |
1df54588fbecf735c10cf5ab2e04e5e591e994ab5c6d69ba7ed0f79146304f32
|