# ofd2pdf **Repository Path**: zrd01/ofd2pdf ## Basic Information - **Project Name**: ofd2pdf - **Description**: OFD转PDF/PNG转换器是一个基于Python开发的库,用于将OFD(Open Fixed-layout Document)格式的文件转换为PDF(Portable Document Format)或PNG格式。该工具支持解析OFD文件的各种元素,包括文本、路径、图像、二维码等,并将其准确地转换为目标格式,保留原始文档的布局和样式。 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2026-01-14 - **Last Updated**: 2026-04-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OFD2PDF OFD转PDF/PNG转换器是一个基于Python开发的库,用于将OFD(Open Fixed-layout Document)格式的文件转换为PDF(Portable Document Format)或PNG格式。该工具支持解析OFD文件的各种元素,包括文本、路径、图像、二维码等,并将其准确地转换为目标格式,保留原始文档的布局和样式。 ## 功能特点 - OFD文件解压与解析 - 页面内容渲染(文本、路径、图像) - 二维码识别与处理 - 印章与数字签名处理 - PDF文件生成 - PNG格式输出支持 - 支持批量转换 - 支持文件路径或二进制数据输入 - 支持内存输出或文件输出 - 提供API接口,方便第三方调用 - 命令行工具支持 ## 技术栈 | 技术/库 | 用途 | 版本要求 | |---------|------|---------| | Python | 开发语言 | 3.6+ | | PyPDF2 | PDF文件操作 | 3.0.0+ | | reportlab | PDF生成 | 3.6.0+ | | qrcode | 二维码生成 | 7.0+ | | Pillow | 图像处理 | 9.0.0+ | | PyMuPDF | PDF转PNG | 1.22.0+ | ## 安装方法 ### 使用pip安装 ```bash pip install ofd2pdf ``` ### 从源码安装 ```bash # 克隆仓库 git clone cd ofd2pdf # 安装依赖 pip install -r requirements.txt # 安装库 pip install -e . ``` ## API使用示例 ### 基本用法 ```python from ofd2pdf import OFD2PDF # 创建转换器实例 converter = OFD2PDF("input.ofd") # 执行转换 converter.convert() # 可选:转换为PNG converter.pdf_to_png("output.png", dpi=300) ``` ### 简洁API ```python from ofd2pdf import ofd_convert # 文件输入,PDF文件输出 pdf_path = ofd_convert("input.ofd", output_format="pdf", output_path="output.pdf") print(f"PDF文件已生成: {pdf_path}") # 二进制输入,PDF内存输出 with open("input.ofd", "rb") as f: ofd_binary = f.read() pdf_binary = ofd_convert(ofd_binary, output_format="pdf", output_path=None) # 文件输入,PNG文件输出 png_paths = ofd_convert("input.ofd", output_format="png", output_path="output.png", dpi=200) print(f"PNG文件已生成: {png_paths}") # 二进制输入,PNG内存输出 with open("input.ofd", "rb") as f: ofd_binary = f.read() png_binaries = ofd_convert(ofd_binary, output_format="png", output_path=None, dpi=300) ``` ## 命令行工具使用 ### 基本用法 ```bash ofd2pdf input.ofd ``` ### 指定输出文件 ```bash ofd2pdf input.ofd -o output.pdf ``` ### 批量转换目录中的所有OFD文件 ```bash ofd2pdf input_dir/ -o output_dir/ ``` ### 转换为PNG格式 ```bash ofd2pdf input.ofd -f png -d 300 ``` ### 命令行参数说明 ``` usage: ofd2pdf [-h] [-o OUTPUT] [-f {pdf,png}] [-d DPI] [input_sources ...] OFD转换工具,支持转换为PDF或PNG格式 positional arguments: input_sources 输入OFD文件路径或目录 optional arguments: -h, --help 显示帮助信息 -o OUTPUT, --output OUTPUT 输出文件/目录路径,默认为自动生成 -f {pdf,png}, --format {pdf,png} 输出格式,默认为pdf -d DPI, --dpi DPI 输出PNG时的DPI,默认为300 ``` ## 注意事项 1. **依赖安装**:使用前需安装必要的依赖 2. **中文字体支持**:工具尝试使用系统中的中文字体(宋体、黑体、楷体) 3. **JBIG2格式支持**:对于JBIG2格式的图像,工具依赖外部工具`jbig2dec`进行转换 4. **性能考虑**:转换大文件时可能需要较多内存 5. **临时文件**:工具会在转换过程中生成临时文件 ## 许可证 本项目采用MIT许可证,可自由使用和修改。 ## 版本历史 - v1.0:基础OFD转PDF功能 - v2.0:增加印章处理、二维码识别、批量转换等功能 - v2.1:增加统一API接口ofd_convert,支持二进制输入和内存输出