A Python library for data extraction, analysis, conversion & manipulation of OFD (China national open fixed-layout document standard GB/T 33190) documents.
Project description
ofdreader
English | 中文
ofdreader is a Python library for data extraction, analysis, conversion & manipulation of OFD (Open Fixed-layout Document; China national standard GB/T 33190—2016) documents.
Install
pip install ofdreader
Development:
pip install -e ".[dev]"
pytest
Quick start
from ofdreader import OfdReader, OfdWriter, ofd_to_pdf, ofd_to_pdf_layout
reader = OfdReader("document.ofd")
print(reader.metadata["Author"])
print(reader.page_count)
text = reader.pages[0].extract_text()
full_text = reader.extract_text() # keeps paragraph breaks, joins line wraps
# flat = reader.extract_text(preserve_layout=False) # single continuous string
writer = OfdWriter()
writer.append(reader)
writer.metadata["Author"] = "Updated Author"
writer.write("copy.ofd")
# Export current extracted paragraphs to a simple PDF
ofd_to_pdf("document.ofd", "document.txt-layout.pdf")
# Export with approximate original fonts/layout from OFD XML
ofd_to_pdf_layout("document.ofd", "document.layout.pdf")
Merge an extra page from another file:
writer = OfdWriter()
writer.append(OfdReader("a.ofd"))
writer.append_pages(OfdReader("b.ofd"), pages=[0])
writer.write("merged.ofd")
Scope (v0.1)
- Open
.ofdpackages (ZIP) from path, bytes, or file-like objects - Read
DocInfometadata, page list, outlines - Extract plain text from
TextObject/TextCode(default keeps paragraph breaks, joins wrapped lines) - Clone packages, update metadata, append pages across documents
- Export extracted text paragraphs to PDF (
ofd_to_pdf, optionalreportlab) - Export approximate original layout PDF (
ofd_to_pdf_layout)
Not included yet: full layout rendering, digital signatures, annotations, creating new glyph-mapped text.
Related projects
- easyofd — OFD ↔ PDF/image conversion
- PyPI name
pyofdis a different library (tax receipt OFD providers)
License
MIT — see LICENSE.
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
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 ofdreader-0.1.0.tar.gz.
File metadata
- Download URL: ofdreader-0.1.0.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efeeb7553b6596f05fb8acc915ba92042d2ed0476d718a0bf8b391afc5c066ec
|
|
| MD5 |
8b6bbd5fa9879623e33ac9e71641a210
|
|
| BLAKE2b-256 |
75d6ffd59a159d1578e94e057d8b6042a77b29612ef79ad76ee2112e3bf6f32a
|
Provenance
The following attestation bundles were made for ofdreader-0.1.0.tar.gz:
Publisher:
python-publish.yml on CY202227/ofdreader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ofdreader-0.1.0.tar.gz -
Subject digest:
efeeb7553b6596f05fb8acc915ba92042d2ed0476d718a0bf8b391afc5c066ec - Sigstore transparency entry: 1688870327
- Sigstore integration time:
-
Permalink:
CY202227/ofdreader@a41f16f7ffce25b58ead2e3e677809b29bfd07bc -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/CY202227
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a41f16f7ffce25b58ead2e3e677809b29bfd07bc -
Trigger Event:
release
-
Statement type:
File details
Details for the file ofdreader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ofdreader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16eda85b84692916aff29de0ccca67c865ad69fa1a84dd8e221f816ed9dee832
|
|
| MD5 |
4d37824eede309705272e99c61a500d3
|
|
| BLAKE2b-256 |
c5bba422054775a9053ce0a2392b51483f4b7de4955ff91e5266d6e6c4eadda8
|
Provenance
The following attestation bundles were made for ofdreader-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on CY202227/ofdreader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ofdreader-0.1.0-py3-none-any.whl -
Subject digest:
16eda85b84692916aff29de0ccca67c865ad69fa1a84dd8e221f816ed9dee832 - Sigstore transparency entry: 1688870405
- Sigstore integration time:
-
Permalink:
CY202227/ofdreader@a41f16f7ffce25b58ead2e3e677809b29bfd07bc -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/CY202227
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a41f16f7ffce25b58ead2e3e677809b29bfd07bc -
Trigger Event:
release
-
Statement type: