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.5.tar.gz
(29.3 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.5.tar.gz.
File metadata
- Download URL: pdf2html_engine-1.0.5.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fe0dbfb364c0ef1c0319e2645b10e17a7422e20832416e5be3e0e178d71397b
|
|
| MD5 |
4ce857705377d7e1458814baea813973
|
|
| BLAKE2b-256 |
228e55952bd3944b41d406e66d7fe3b3552106e1599b21f42f3945e257683dd8
|
File details
Details for the file pdf2html_engine-1.0.5-py3-none-any.whl.
File metadata
- Download URL: pdf2html_engine-1.0.5-py3-none-any.whl
- Upload date:
- Size: 27.9 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 |
24fc7d0ec0e929dbc3448ffb3cbaae528ef65572097bcc23ee55be8dc6aa88c5
|
|
| MD5 |
4ebeca984be4126b4c21179dbcf819cc
|
|
| BLAKE2b-256 |
c2b26d5c197aa23f1ad2718f2f0712981ae7e8422802fb7295a64912315eb237
|