Overview of pdf2docx
masterPyMuPDF, parsing the layout using rule-based logic, and generating the resulting DOCX files using python-docx.repository·master·Indexed 26 days ago
https://github.com/artifexsoftware/pdf2docxA Python library for converting PDF files into DOCX documents using PyMuPDF for data extraction and python-docx for file generation. It features table extraction, a Command Line Interface (CLI) with multi-processing support, and a tkinter-based Graphical User Interface (GUI). The library is relicensed under the MIT License and is no longer actively maintained by Artifex.
PyMuPDF, parsing the layout using rule-based logic, and generating the resulting DOCX files using python-docx.⚠️ Note: pdf2docx is no longer actively maintained by Artifex.
The project has been relicensed under the MIT License, allowing the community to use, fork, and maintain it. While community pull requests are welcome, Artifex no longer provides active development.
If you require a full-featured PDF processing library, the maintainers suggest considering PyMuPDF or MuPDF.NET.
pdf2docx repository locally, navigate to the root directory to install it using setup.py.To remove pdf2docx from your environment, use pip uninstall.
pip uninstall pdf2docxNavigate to the docs directory and use sphinx-build to generate HTML files. The output will be placed in the build/html directory.
If you have updated CSS or assets in the _static folder, use the -a flag to ensure all assets are included in the build.
To install the latest version directly from the master branch on GitHub (which may be newer than the version available on PyPI), use the following command:
pip install git+git://github.com/ArtifexSoftware/pdf2docx.git@master --upgradeFor a simpler one-line conversion of all pages, use the parse method from pdf2docx.
from pdf2docx import parse
pdf_file = '/path/to/sample.pdf'
docx_file = 'path/to/sample.docx'
# convert pdf to docx
parse(pdf_file, docx_file)To speed up conversion, you can enable multi-processing using the --multi_processing flag. You can also control the number of CPU cores used with the --cpu_count flag.
--multi_processing: Set to True to enable multi-processing. If no count is specified, it defaults to the total number of available CPUs.--cpu_count: Specifies the exact number of CPUs to use for the operation.password argument when initializing the Converter class.You can convert a PDF to DOCX using either the Converter class or the high-level parse function. Both methods convert all pages by default.
from pdf2docx import Converter
pdf_file = '/path/to/sample.pdf'
docx_file = 'path/to/sample.docx'
# Using Converter class
cv = Converter(pdf_file)
cv.convert(docx_file) # all pages by default
cv.close()To extract tables from a PDF file, use the Converter class from pdf2docx. Initialize the Converter with the path to your PDF, call extract_tables() specifying the range of tables to extract via start and end parameters, and ensure you call close() to release resources. The extracted tables are returned as a list of lists, where each inner list represents a row in the table.
from pdf2docx import Converter
pdf_file = '/path/to/sample.pdf'
cv = Converter(pdf_file)
tables = cv.extract_tables(start=0, end=1)
cv.close()
for table in tables:
print(table)The pdf2docx command line interface supports three primary commands:
convert: Converts a PDF file to a DOCX file.debug: Converts a single PDF page and plots layout information for debugging purposes.table: Extracts table content from PDF pages.$ pdf2docx --help