/install pdf2ofd
PDF to OFD High-Fidelity Converter
🎯 Purpose
A specialized skill for converting PDF documents into the Chinese National Standard OFD (GB/T 33190-2016) format. Optimized for Electronic Invoices (OFD版式发票) with advanced rendering capabilities that exceed standard conversion libraries.
✨ Key Features
- High-Fidelity Text Placement: Uses character-level positioning (
DeltaXarrays) and baseline origin data extracted viarawdictto ensure text layout is 100% identical to the source PDF. - Advanced Vector Graphics: Directly extracts original stroke colors, fill colors, and line widths. Supports complex path types and fill instructions.
- Transparency Preservation: Fully supports
AlphaandFillOpacityfor vector paths andSMasktransparency for images (e.g., electronic seals and signatures). - Cross-Platform Font Mapping: Intelligent mapping of macOS-specific (STSong, STKaiti) and Windows-specific font names to standardized OFD font names (宋体, 楷体, 黑体).
- In-Memory Packaging: Generates the final OFD zip structure entirely in memory to avoid temporary file clutter and ensure security.
- Color Snapping: Heuristic "Invoice Red" correction (
128 0 0) for financial documents while preserving non-standard colors.
🛠️ Usage Instructions
When a user asks to convert a PDF or a "High-Fidelity" invoice to OFD:
-
Direct Execution:
python3 pdf2ofd.py \x3Cinput_path.pdf> [output_path.ofd] -
Plugin Integration: The script implements a
PDF2OFDConverterclass that can be easily imported and used in other Python workflows.
Example Output
Success: /path/to/invoice.ofd
📦 Requirements
Dependencies required in the environment:
PyMuPDF (fitz): For advanced PDF parsing and raw character data extraction.Pillow: For image processing and transparency handling.easyofd: The base library for OFD structure (extended via internal monkey patches).xmltodict: For XML manipulation.
💡 Notes
- This skill uses deep monkey-patching on
easyofdto fix known library limitations regarding character positioning and resource ID tracking. - The conversion process assumes standard Chinese fonts (SimSun, KaiTi, SimHei) are available on the viewing system.
- Zero-copy resource handling: Images are extracted and re-compressed as PNG/JPG only when necessary to preserve quality.
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install pdf2ofd - 安装完成后,直接呼叫该 Skill 的名称或使用
/pdf2ofd触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
pdf2ofd 是什么?
Converts PDF documents (invoices, reports) to High-Fidelity OFD format with pixel-perfect precision. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 238 次。
如何安装 pdf2ofd?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install pdf2ofd」即可一键安装,无需额外配置。
pdf2ofd 是免费的吗?
是的,pdf2ofd 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
pdf2ofd 支持哪些平台?
pdf2ofd 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 pdf2ofd?
由 xzw(@xzw)开发并维护,当前版本 v1.0.2。