Skip to main content

A specification-driven, pure-Python Word binary .doc to .docx converter

Project description

doc2docx

doc2docx is a specification-driven, pure-Python converter for Microsoft Word 97–2003 binary .doc files. It does not invoke Microsoft Word, LibreOffice, COM, Java, or an external conversion executable.

The current M0–M5b implementation supports unencrypted CFB/OLE Word documents, the 0Table/1Table selection mechanism, CLX piece tables, compressed and UTF-16LE text pieces, and the main document story. It reads CHPX/PAPX FKPs and preserves a useful first set of direct character and paragraph properties. It also reads the SttbfFfn font table, emits DOCX font definitions, converts paragraph/character styles with basedOn inheritance, resolves style-relative toggles, and applies simple and complex piece-level PRMs in specification order. It reconstructs tables from DOC cell/row markers, including nested tables, and preserves their column grid, preferred cell widths, basic merges, alignment, row sizing, Word 97 borders and shading, and default or range-specific cell margins. It also follows main-story PlcfSed records through Sed.fcSepx to each Sepx.grpprl, reconstructing single or multiple sections. Section-break types, paper size, portrait/landscape orientation, page margins, header/footer distance, and gutter width are emitted as WordprocessingML section properties. It parses PlcfHdd, removes each story's guard paragraph, preserves the six default/even/first header and footer positions per section, and retains empty-story inheritance. Header/footer parts, relationships, first-page rules, and the DOP facing-pages setting are written as native DOCX package parts.

Usage

python -m pip install msdoc2docx
doc2docx input.doc
doc2docx input.doc -o output.docx --report report.json
doc2docx inspect input.doc --json

To install from a local source checkout instead, run python -m pip install ..

Python API:

from doc2docx import convert

result = convert("input.doc", "output.docx")
print(result.report.to_dict())

M5b currently preserves bold, italic, strike, double strike, capitalization, hidden text, underline, text color, highlight, font size, vertical alignment, paragraph justification, indents, spacing, line spacing, and keep/page-break flags, font names, paragraph/character style references, style inheritance, basic section/page layout, and ordinary paragraph/table content in headers and footers. Conditional table styles, newer color-based table shading, cell spacing, numbering styles, multi-column layout, page-number settings, header/footer textboxes and shapes, other secondary stories, images, live fields, embedded objects, and encrypted documents are intentionally deferred to later iterations. Unsupported or lossy content is reported rather than silently treated as fully converted.

Tests

The test suite uses only the Python standard library:

PYTHONPATH=src python -m unittest discover -v

It includes constructed CFB version 3/version 4 files, regular and mini streams, both Table stream variants, mixed compressed/UTF-16 text pieces, UTF-16 surrogate pair coordinates, CHPX/PAPX and piece-level PRM formatting, font/style table parsing, nested table reconstruction, grids, cell margins and shading, PlcfSed and Sepx page-layout parsing, multi-section break placement, PlcfHdd guard and story mapping, header/footer OPC relationships, malformed input checks, CLI coverage, and end-to-end DOCX package validation.

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

msdoc2docx-0.7.0.tar.gz (59.0 kB view details)

Uploaded Source

Built Distribution

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

msdoc2docx-0.7.0-py3-none-any.whl (57.8 kB view details)

Uploaded Python 3

File details

Details for the file msdoc2docx-0.7.0.tar.gz.

File metadata

  • Download URL: msdoc2docx-0.7.0.tar.gz
  • Upload date:
  • Size: 59.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for msdoc2docx-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e48b9aa15ee51a3d058c97550704a0bfb518a75c0fe6478eb806bfa858f63adb
MD5 c799e931856658a8c2320aa35208425f
BLAKE2b-256 550f72ba9690c46b30e80538c98070ec8666a84efeb69ed9f75ed353890e6b6d

See more details on using hashes here.

File details

Details for the file msdoc2docx-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: msdoc2docx-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 57.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for msdoc2docx-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8893909ddb037e698119bbea41c24ccdc26998a0a32f06e542f470b71630178e
MD5 235bc5528582732ed364744d11888193
BLAKE2b-256 f80c81147b71208aba5587cbfd78e38f92e455a8117b6e7b253b17e17f8f35e9

See more details on using hashes here.

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