Registry / data / pdf2docx

pdf2docx

JSON →
library0.5.13pypypi✓ verified 21d ago

pdf2docx is an open-source Python library designed for converting PDF files into editable Microsoft Word DOCX documents. It leverages PyMuPDF for PDF data extraction, applies rule-based parsing for layout analysis, and utilizes python-docx for generating the final DOCX output. The library aims to extract text, images, and tables while preserving the original layout and formatting. The current version is 0.5.12, released on March 9, 2026.

pip install pdf2docx
INSTALL
IMPORT
SIG · PDF2DOCX
P
pdf2docx
datapythonv0.5.13
Install
8.4s avg
Import
1996ms
Disk
346MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 8.4s · import 1.996s · 342MB
346MB installed
● package 346MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Converter
from pdf2docx import Converter
parse
from pdf2docx import parse
pdf2docx.parse()
The `parse` function is directly available from the top-level package, not as a method of a class.

This quickstart demonstrates how to convert a PDF file to a DOCX file using the `Converter` class. It shows how to initialize the converter with a PDF file, perform the conversion, and close the converter. The example includes creating a simple dummy PDF if no existing file is provided to ensure it's runnable.

import os from pdf2docx import Converter # Create a dummy PDF file for demonstration if it doesn't exist dummy_pdf_content = b"%PDF-1.4\n1 0 obj <</Type /Page /Contents 2 0 R>> endobj\n2 0 obj <</Length 11>> stream\nBT /F1 12 Tf 72 712 Td (Hello World) Tj ET\nendstream endobj\nxref\n0 3\n0000000000 65535 f\n0000000009 00000 n\n0000000074 00000 n\ntrailer <</Size 3 /Root 1 0 R>> startxref 122\n%%EOF" pdf_file_path = "sample.pdf" docx_file_path = "output.docx" if not os.path.exists(pdf_file_path): with open(pdf_file_path, "wb") as f: f.write(dummy_pdf_content) print(f"Created dummy PDF: {pdf_file_path}") try: # Create a Converter object cv = Converter(pdf_file_path) # Convert the PDF to DOCX cv.convert(docx_file_path, start=0, end=None) # start and end are 0-based, None means to the end cv.close() print(f"Conversion successful: {pdf_file_path} -> {docx_file_path}") except Exception as e: print(f"An error occurred during conversion: {e}") finally: # Clean up dummy PDF if it was created if os.path.exists(pdf_file_path) and dummy_pdf_content: os.remove(pdf_file_path) print(f"Cleaned up dummy PDF: {pdf_file_path}") if os.path.exists(docx_file_path): # In a real scenario, you might want to keep the output, but for a quickstart, we clean up. # os.remove(docx_file_path) pass # Keep the output docx for user inspection
pdf2docx --version
Debug
Known issues
deprecatedThe `pdf2docx` library is no longer actively maintained by its original developer, Artifex. While the repository is open for community contributions, active development and official maintenance by Artifex have ceased.
fix
Be aware that new features or prompt bug fixes from the original maintainers are unlikely. Consider community forks or alternative libraries if active development and support are critical for your project.
affects: 0.5.x onwards
gotchaThe library primarily processes text-based PDFs and does not perform Optical Character Recognition (OCR). Scanned PDF documents, which are essentially images, will not have their text content extracted or converted to editable DOCX text.
fix
For scanned PDFs, you must run an OCR tool on the PDF first to convert images of text into actual text before using `pdf2docx` for conversion.
affects: All versions
gotchaComplex PDF layouts, especially those with intricate tables, multi-column designs, or unusual text flows, may not be perfectly replicated in the converted DOCX file due to the library's rule-based parsing method.
fix
Test with representative PDF documents to assess conversion fidelity. For critical layout preservation, manual adjustments to the output DOCX might be necessary, or consider alternative conversion methods for highly complex documents.
affects: All versions
gotchaThe library is primarily designed for left-to-right languages and standard reading directions. Documents with right-to-left languages or significant text transformations/rotations might not convert accurately.
fix
Verify output for documents in non-left-to-right languages or with complex text orientations. No direct fix within `pdf2docx` for these limitations.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pdf2docx'
The 'pdf2docx' library is not installed in the Python environment being used, or there is a typo in the import statement.
fix
Ensure the library is correctly installed using pip: `pip install pdf2docx`
ImportError: cannot import name 'Converter' from partially initialized module 'pdf2docx' (most likely due to a circular import)
This error typically occurs when your Python script file is named `pdf2docx.py`, causing Python to try and import your script instead of the actual installed library, leading to a circular dependency.
fix
Rename your Python script file to anything other than `pdf2docx.py` (e.g., `convert_pdf.py`).
AttributeError: 'Rect' object has no attribute 'get_area'
This issue often indicates an incompatibility or version mismatch between `pdf2docx` and its underlying dependency, `PyMuPDF` (also known as `fitz`), where a method or attribute expected by `pdf2docx` is missing or changed in the `PyMuPDF` version.
fix
Upgrade `pdf2docx` to its latest version: `pip install --upgrade pdf2docx`. If the issue persists, check the `pdf2docx` documentation or GitHub issues for specific `PyMuPDF` version requirements and adjust your `PyMuPDF` installation accordingly (e.g., `pip install 'PyMuPDF==1.23.8'`).
[ERROR] Ignore page X due to making page error: invalid literal for int() with base 16: 'x1'
This error occurs when `pdf2docx` encounters complex or malformed elements on a specific PDF page, particularly during table parsing or layout analysis, and fails to interpret them as valid hexadecimal integers.
fix
Try disabling lattice table parsing, as this often resolves issues with intricate table structures: `cv.convert(docx_file, start=0, end=None, parse_lattice_table=False)`.
Upgrade
Version history
0.5.13latest on PyPI · released May 1, 2026
Audit
Dependencies
PyMuPDFrequiredUsed for extracting data (text, images, drawings) from PDF files.
python-docxrequiredUsed for generating the DOCX output file.
Agent activity
7 hits · last 30 days
node
4
Resources
pdf2docx — pip install pdf2docx · libregistry