Skip to main content

OFD → PDF 转换工具

基于 ofd-utilityofd-cli,用 Python 封装:OFD 渲染为页面图片 → 合成为 PDF

官方构建支持 Windows / Linux,可通过 PyPI 平台 wheel 安装,或下载 独立可执行文件

原理

  1. 调用 ofd-cli render 将各页光栅化为 PNG(或其它格式)
  2. 用 Pillow 按页序合并为多页 PDF

安装(PyPI)

pip install ofd2pdf
# 或
uv add ofd2pdf

安装的是当前平台的 wheel,内置对应系统的 ofd-cli 二进制,无需本机安装 Rust。

纯源码 sdist 包含 ofd-cli。若仅装到 sdist,请自行构建二进制或设置 OFD_CLI

独立二进制(无 Python 环境)

GitHub Release 产物中的 ofd2pdf-<os>-<arch>(PyInstaller onefile)可直接运行:

./ofd2pdf-linux-x86_64 input.ofd -o out.pdf
ofd2pdf-windows-amd64.exe input.ofd -o out.pdf

本地开发

uv sync --group dev
bash scripts/build_ofd_cli.sh    # 或 build_ofd_cli.ps1
uv run ofd2pdf sample.ofd -o out.pdf --dpi 200

也可手动指定:

export OFD_CLI=/path/to/ofd-cli      # Unix
set OFD_CLI=C:\path\to\ofd-cli.exe # Windows

用法

ofd2pdf sample.ofd
ofd2pdf sample.ofd -o out.pdf --dpi 200
ofd2pdf sample.ofd --keep-images --images-dir ./pages
ofd2pdf sample.ofd --info

库调用:

from ofd2pdf import convert_ofd_to_pdf

pdf = convert_ofd_to_pdf("sample.ofd", "out.pdf", dpi=150)

发布(仅 GitHub Actions)

打包与上传 只在 CI 完成:打 v* tag 后,Actions 会构建多平台 wheel / sdist / 独立二进制,挂到 GitHub Release,并自动上传 PyPI。

git tag v0.2.1
git push origin v0.2.1
# 进度: https://github.com/rhq-git/ofd2pdf/actions

也可在 Actions → ReleaseRun workflow,填已有 tag 补打并重新上传(PyPI 已有文件会 skip-existing)。

前置:在 PyPI 为该项目配置 Trusted Publishing(OIDC),Workflow 填 release.yml

产物示例(Windows / Linux):

  • ofd2pdf-*-py3-none-win_amd64.whl
  • ofd2pdf-*-py3-none-manylinux*.whl(经 auditwheel 修复;PyPI 不接受裸 linux_*
  • ofd2pdf-windows-amd64.exe / ofd2pdf-linux-x86_64

目录结构

ofd2pdf/
├── src/ofd2pdf/           # Python 包
│   └── bin/               # 构建时放入的 ofd-cli(随平台 wheel 发布)
├── scripts/               # ofd-cli / standalone 构建脚本(供 CI / 本地开发)
├── hatch_build.py         # 平台 wheel 标记
└── .github/workflows/     # CI 与 Release

许可证

本项目为 MIT(见 LICENSE)。

捆绑 / 依赖的 ofd-utilityofd-cli)同为 MIT;上游版权与许可全文见 NOTICE

Release files for ofd2pdf 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ofd2pdf 0.0.2
File Size Uploaded
ofd2pdf-0.0.2.tar.gz 10.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for ofd2pdf 0.0.2
File Interpreter ABI Platform
ofd2pdf-0.0.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
ofd2pdf-0.0.2-py3-none-manylinux_2_35_x86_64.whl Python 3 none Linux glibc 2.35+ x86-64 Details

Total release size: 5.0 MB

Release files / ofd2pdf-0.0.2.tar.gz

Download URL ofd2pdf-0.0.2.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3d5cfb085a419ee56895a082876503d7a9d1871db9148e98e82fc9240c5ce3c7
BLAKE2b-256 checksum
How to use checksums
e67a5bf09a3afc5d3b28fd054874c20a0e8c5dcd11c2c8bfeb1c8dfc1f6000f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / ofd2pdf-0.0.2-py3-none-win_amd64.whl

Download URL ofd2pdf-0.0.2-py3-none-win_amd64.whl
Size 2.2 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
996a4ce988b010be8c2303f856dc8b7724bc6b870a34391cef0f380cc62a8317
BLAKE2b-256 checksum
How to use checksums
b3abbf2191d376330f18c5487ad429c2242f8afbd4fd192f693e511a91011fe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / ofd2pdf-0.0.2-py3-none-manylinux_2_35_x86_64.whl

Download URL ofd2pdf-0.0.2-py3-none-manylinux_2_35_x86_64.whl
Size 2.7 MB
Tags Linux glibc 2.35+ x86-64 Python 3
SHA-256 checksum
How to use checksums
a4c2bd623f0a4b1196cbf7c7f40240b4e081c4076a2ed96ceb43a42150188410
BLAKE2b-256 checksum
How to use checksums
dfb004b52d205db93146c90cf7f796e6b8f2c57839972eb652a0b9239952eaf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.2 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page