pdf2docx Documentation

repository·master·Indexed 26 days ago

https://github.com/artifexsoftware/pdf2docx

A 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.

Tokens
2K
Snippets
8
Records
26
Agent score
85%

What's inside pdf2docx

  1. Project Status and Licensing

    master

    ⚠️ 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.

  2. Build HTML documentation using Sphinx

    master

    Navigate 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.

  3. Enable Multi-Processing in pdf2docx CLI

    master

    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.
  4. Convert all pages of a PDF to DOCX

    master

    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()
  5. Extract tables from a PDF using Converter

    master

    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)