Convert PDF files to OFD (Open Fixed-layout Document) format
Project description
pdf2ofd
Convert PDF files to OFD (Open Fixed-layout Document) format — a Chinese national standard for electronic documents (GB/T 33190-2016).
Features
- Full vector path conversion (SVG → OFD), supporting all SVG path commands:
M L H V Q C S T A Z - Native OFD path commands:
M L Q B A C— no lossy approximation - Image extraction with RGBA transparency support
- Multi-page PDF support
- Command-line interface and Python API
Installation
pip install pdf2ofd
Note: Requires
pymupdf>=1.24.0,<1.25.0. Newer versions have SVG export issues that affect conversion accuracy.
Usage
Command Line
# Convert all pages
pdf2ofd input.pdf output.ofd
# Convert specific pages (0-indexed)
pdf2ofd input.pdf output.ofd --pages 0,1,2
# Suppress output
pdf2ofd input.pdf output.ofd --quiet
# Show version
pdf2ofd --version
Python API
from pdf2ofd import convert
# Convert all pages
convert("input.pdf", "output.ofd")
# Convert specific pages
convert("input.pdf", "output.ofd", pages="0,1,2")
# Suppress progress output
convert("input.pdf", "output.ofd", verbose=False)
How It Works
PDF
├── PyMuPDF SVG export → vector paths (glyphs, lines, curves)
└── PyMuPDF image API → images (with RGBA/transparency)
↓
OFD
- Vector paths are extracted from PyMuPDF's SVG export and converted to OFD
AbbreviatedDataformat - Images are extracted directly from PDF resources via
get_image_rects(), preserving original quality and supporting multiple placements of the same image - All SVG path commands are mapped to native OFD equivalents — cubic Bézier (
C) maps to OFDB, arcs (A) map to OFDA
Requirements
- Python >= 3.10
- pymupdf >= 1.24.0, < 1.25.0
- lxml >= 4.9
- pillow >= 9.0
License
MIT
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
pdf2ofd-0.1.0.tar.gz
(11.2 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
pdf2ofd-0.1.0-py3-none-any.whl
(12.2 kB
view details)
File details
Details for the file pdf2ofd-0.1.0.tar.gz.
File metadata
- Download URL: pdf2ofd-0.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26cd23414171ec511f0653d74edc2159efd10c4061e4e368eb674585f7f265bf
|
|
| MD5 |
56cc8f0664d5e28c29180483215573e2
|
|
| BLAKE2b-256 |
bbb8a319d726a4841caddba038e120ada79ab858a3dfacd748833371b3f40fa3
|
File details
Details for the file pdf2ofd-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pdf2ofd-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f271d77bfb71ca9bc3e30905ba59ff38019eb576765e25ace0caebba8f3790a
|
|
| MD5 |
a0631c486ce7d009b0356ec5f76f1077
|
|
| BLAKE2b-256 |
92d318e4bfcf7e527f42e1b9e753176abb9ba30d0453db719bb4b649b3331294
|