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 pdf2docxVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
Verify output for documents in non-left-to-right languages or with complex text orientations. No direct fix within `pdf2docx` for these limitations.
Ensure the library is correctly installed using pip: `pip install pdf2docx`
Rename your Python script file to anything other than `pdf2docx.py` (e.g., `convert_pdf.py`).
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'`).
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)`.