Skip to main content

pdf2docx

pdf2docx-test pdf2docx-publish

  • Parse text, table and layout from PDF file with PyMuPDF
  • Generate docx with python-docx

Features

  • Parse and re-create text format
    • font style, e.g. font name, size, weight, italic and color
    • highlight, underline, strike-through converted from docx
    • highlight, underline, strike-through applied from PDF annotations
  • Parse and re-create list style
  • Parse and re-create table
    • border style, e.g. width, color
    • shading style, i.e. background color
    • merged cells
  • Rebuild page layout in docx
    • paragraph layout: horizontal and vertical spacing
    • in-line image

Limitations

  • text-based PDF file only
  • Normal reading direction only
    • horizontal paragraph/line/word
    • no word transformation, e.g. rotation
  • No floating images
  • Full borders table only

Installation

From Pypi

$ pip install pdf2docx

From source code

Clone or download this project, and navigate to the root directory:

$ python setup.py install

Or install it in developing mode:

$ python setup.py develop

Uninstall

$ pip uninstall pdf2docx

Usage

By range of pages

$ pdf2docx test.pdf test.docx --start=5 --end=10

By page numbers

$ pdf2docx test.pdf test.docx --pages=5,7,9
$ pdf2docx --help

NAME
    pdf2docx - Run the pdf2docx parser

SYNOPSIS
    pdf2docx PDF_FILE DOCX_FILE <flags>

DESCRIPTION
    Run the pdf2docx parser

POSITIONAL ARGUMENTS
    PDF_FILE
        PDF filename to read from
    DOCX_FILE
        DOCX filename to write to

FLAGS
    --start=START
        first page to process, starting from zero
    --end=END
        last page to process, starting from zero
    --pages=PAGES
        range of pages

NOTES
    You can also use flags syntax for POSITIONAL ARGUMENTS

As a source package

import os
from pdf2docx.reader import Reader
from pdf2docx.writer import Writer

dir_output = '/path/to/output/dir/'
filename = 'demo-text'
pdf_file = os.path.join(dir_output, f'{filename}.pdf')
docx_file = os.path.join(dir_output, f'{filename}.docx')

pdf = Reader(pdf_file, debug=True)  # debug mode to plot layout in new PDF file
docx = Writer()

for page in pdf[0:1]:
    # parse raw layout
    layout = pdf.parse(page)
    # re-create docx page
    docx.make_page(layout)

docx.save(docx_file)
pdf.close()

Sample

sample_compare.png

License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf2docx-0.0.1.tar.gz (411.4 kB view details)

Uploaded Source

Built Distribution

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

pdf2docx-0.0.1-py3-none-any.whl (59.1 kB view details)

Uploaded Python 3

File details

Details for the file pdf2docx-0.0.1.tar.gz.

File metadata

  • Download URL: pdf2docx-0.0.1.tar.gz
  • Upload date:
  • Size: 411.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pdf2docx-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2d68b41b182d601b999fc6882612b243922561ce985e7c61f1e2a2c94ca6a6fa
MD5 8794041a217d1c219edec13af665d860
BLAKE2b-256 4907846087e2dfb0cbc95499c4c8f63b6629a5fd26ddd757685e73f16b1449d9

See more details on using hashes here.

File details

Details for the file pdf2docx-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pdf2docx-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 59.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pdf2docx-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0cf2e11bdf0ac04bb155778451915d22641b898e03e97703813b97e74239483
MD5 6122a0b9fdeae98463c2bf0d35710561
BLAKE2b-256 14a7e40d87b81cc7c8a1f13d65f775c1ef54efc2d4cfbafe9306eebdfa9e62ba

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.13

2 files

0.5.12

2 files

0.5.11

2 files

0.5.10

2 files

0.5.9

2 files

0.5.8

2 files

0.5.7

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

This release

0.0.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page