Skip to main content

Convert PDF, DOCX, CSV, and image files to Markdown.

Project description

documint2md

Convert PDF, DOCX, CSV, and image files to Markdown from the command line or from Python.

documint2md installs the doc2md CLI and the doc2md Python package. It is designed for scripts, agents, and documentation pipelines that need predictable Markdown output and clear machine-readable status.

Install

python -m pip install documint2md

Optional extras:

python -m pip install "documint2md[markdown]"       # GFM Markdown formatting
python -m pip install "documint2md[pymupdf4llm]"    # alternate PDF Markdown engine
python -m pip install "documint2md[universal-lite]" # MarkItDown for extra formats
python -m pip install "documint2md[docling]"        # Docling structured conversion
python -m pip install "documint2md[ocr]"            # image and scanned-PDF OCR
python -m pip install "documint2md[all]"            # all published optional features

Python 3.11 or newer is required.

Command Line

Convert one file and write <input stem>.md beside it:

doc2md report.pdf
doc2md notes.docx
doc2md table.csv
doc2md scan.png

Choose an output path:

doc2md report.pdf -o report.md

Write Markdown to stdout:

doc2md report.pdf -o -

Preview without writing a file:

doc2md report.pdf --preview

Run several inputs non-interactively:

doc2md docs/*.pdf --yes

Open the interactive picker:

doc2md

Agent and Automation Usage

Use --json when another program needs a structured result. Diagnostics still go to stderr, and stdout stays reserved for JSON in this mode.

doc2md report.pdf --json
doc2md report.pdf --dry-run --json

Useful automation flags:

doc2md report.pdf --quiet
doc2md report.pdf --debug
doc2md report.pdf --stats
doc2md doctor engines --json

Exit codes:

  • 0: success
  • 2: usage or argument error
  • 3: unsupported format
  • 4: conversion failed
  • 5: output write failed

Output behavior:

  • By default, report.pdf writes report.md in the same directory.
  • -o <file> writes UTF-8 Markdown with \n newlines.
  • -o - writes Markdown to stdout.
  • Errors and diagnostics go to stderr.

Formats and Engines

Default conversions:

  • PDF: text extraction with pdfminer.six
  • DOCX: Mammoth HTML to Markdown
  • CSV: Pandas to Markdown table
  • Images: OCR when the ocr extra is installed

Force a format:

doc2md input.bin --format pdf
doc2md input.bin --format docx
doc2md input.bin --format csv
doc2md input.bin --format image

Use optional engines:

doc2md report.pdf --engine pymupdf4llm
doc2md slides.pptx --format any --engine markitdown
doc2md document.docx --format any --engine docling

Check installed optional engines:

doc2md doctor engines
doc2md doctor engines --json

Markdown Formatting

Every CLI conversion can post-process Markdown:

doc2md table.csv --md-style normalize
doc2md table.csv --md-style gfm
doc2md table.csv --md-style none
  • normalize is the default. It normalizes newlines, strips trailing whitespace, caps blank lines, and ends non-empty output with one trailing newline.
  • gfm formats GitHub Flavored Markdown and requires documint2md[markdown].
  • none leaves converter output unchanged after conversion.

OCR

Install OCR support:

python -m pip install "documint2md[ocr]"

Convert an image:

doc2md scan.png --ocr-lang en

Use OCR for scanned or low-text PDFs:

doc2md scan.pdf --ocr-mode auto --ocr-lang en
doc2md scan.pdf --ocr-mode always --ocr-layout heuristic --md-style gfm

Common OCR options:

doc2md scan.pdf --ocr-device cpu
doc2md scan.pdf --ocr-device gpu:0
doc2md scan.pdf --ocr-render-scale 2.0
doc2md scan.pdf --ocr-min-score 0.5
doc2md scan.pdf --ocr-debug-json debug.json
doc2md scan.png --ocr-debug-image debug.png

The first OCR run may download model files for the OCR backend. Subsequent runs are normally faster.

Python API

from doc2md import (
    any_to_markdown,
    csv_to_markdown,
    docx_to_markdown,
    image_to_markdown,
    pdf_to_markdown,
)

markdown = pdf_to_markdown("report.pdf")

Each public converter accepts str or PathLike input and returns str.

from doc2md import ConversionError, UnsupportedFormatError, pdf_to_markdown

try:
    markdown = pdf_to_markdown("report.pdf")
except UnsupportedFormatError as exc:
    print(f"Unsupported input: {exc}")
except ConversionError as exc:
    print(f"Conversion failed: {exc}")

Profiles

Store reusable defaults in doc2md.toml:

[profiles.fast_pdf]
format = "pdf"
engine = "pdfminer"
md_style = "normalize"

[profiles.ocr_pdf]
format = "pdf"
ocr_mode = "auto"
ocr_lang = "en"
ocr_layout = "heuristic"
md_style = "gfm"

Run with a profile:

doc2md report.pdf --profile fast_pdf
doc2md scan.pdf --profile ocr_pdf

Notes for Reliable Automation

  • Pin the package version in production, for example documint2md==2.0.2.
  • Use --json for structured status and -o - only when stdout should contain Markdown.
  • Use --yes for batch conversions in non-interactive jobs.
  • Use --md-style normalize or --md-style gfm when exact Markdown formatting matters.
  • Run doc2md doctor engines --json in setup checks to confirm optional engines are installed.

Links

Project details


Download files

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

Source Distribution

documint2md-2.0.2.tar.gz (74.7 kB view details)

Uploaded Source

Built Distribution

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

documint2md-2.0.2-py3-none-any.whl (52.6 kB view details)

Uploaded Python 3

File details

Details for the file documint2md-2.0.2.tar.gz.

File metadata

  • Download URL: documint2md-2.0.2.tar.gz
  • Upload date:
  • Size: 74.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for documint2md-2.0.2.tar.gz
Algorithm Hash digest
SHA256 7d4371c4678887167758a8f496d26353fa73589991ed71336cbf919cfa447bc0
MD5 bcc6c8ea5efe1fdfc0b3c5b798b3d2fd
BLAKE2b-256 7dab20e624c8f30e3e5d52abaf35b037d5766be4ae8171dfa3cbac28967bf9e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for documint2md-2.0.2.tar.gz:

Publisher: release-pypi.yml on myucordero/documint2md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file documint2md-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: documint2md-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 52.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for documint2md-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 884d00e8794d5246826370910502d237daee7728200f7963168ca19a2c00c0ca
MD5 dafc01fc70d8a1baf688d072d3961827
BLAKE2b-256 185f31ea0cf986db8bb2e4aef024f68353f7e5eba6db71825cdb197ba91f6302

See more details on using hashes here.

Provenance

The following attestation bundles were made for documint2md-2.0.2-py3-none-any.whl:

Publisher: release-pypi.yml on myucordero/documint2md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page