Skip to main content

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 .ofd packages (ZIP) from path, bytes, or file-like objects
  • Read DocInfo metadata, 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, optional reportlab)
  • 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 pyofd is a different library (tax receipt OFD providers)

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ofdreader-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ofdreader-0.1.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

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

Hashes for ofdreader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efeeb7553b6596f05fb8acc915ba92042d2ed0476d718a0bf8b391afc5c066ec
MD5 8b6bbd5fa9879623e33ac9e71641a210
BLAKE2b-256 75d6ffd59a159d1578e94e057d8b6042a77b29612ef79ad76ee2112e3bf6f32a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ofdreader-0.1.0.tar.gz:

Publisher: python-publish.yml on CY202227/ofdreader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for ofdreader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16eda85b84692916aff29de0ccca67c865ad69fa1a84dd8e221f816ed9dee832
MD5 4d37824eede309705272e99c61a500d3
BLAKE2b-256 c5bba422054775a9053ce0a2392b51483f4b7de4955ff91e5266d6e6c4eadda8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ofdreader-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on CY202227/ofdreader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page