Skip to main content

Document digestion (OCR to Markdown) and composition (Markdown to documents) agent

Project description

document-agent

Document digestion (OCR to Markdown), composition (Markdown to documents), diagram generation, raster image generation, and form filling. Full round-trip support for footnotes, tracked changes, comments, and styles.

Digestion

Convert PDF, images, and Office documents to Markdown.

  • PDF/images: OCR via Mistral Document AI (direct or Azure AI Foundry)
  • DOCX/ODT: pandoc-based extraction preserving footnotes, tracked changes, comments, and document styles
# Basic digest (auto-selects pandoc for DOCX, OCR for PDF/images)
document-agent digest document.docx

# Show all tracked changes and comments
document-agent digest document.docx --track-changes all

# Force OCR pipeline for a scanned DOCX
document-agent digest scanned.docx --mode ocr

# Inline mode (base64-embedded images, prints to stdout)
document-agent digest document.pdf --inline

# With structured annotation extraction
document-agent digest document.pdf --schema schema.py --prompt "Extract all line items"

Round-trip metadata

DOCX digestion preserves four types of metadata that round-trip through compose:

  • Footnotes: [^1] with [^1]: definition text at end
  • Tracked changes: [text]{.insertion author="Name" date="2026-01-01"} / {.deletion ...}
  • Comments: [comment text]{.comment-start id="1" author="Name"}...{.comment-end id="1"}
  • Document styles: YAML front matter block (fonts, sizes, colors, spacing, margins)

Supported input formats: PDF, PNG, JPG, JPEG, WEBP, TIFF, BMP, DOCX, PPTX, XLSX, ODT.

Composition

Convert Markdown to various output formats with style control.

# Basic compose
document-agent compose input.md output.docx --format docx

# With a reference document for style inheritance
document-agent compose input.md output.docx --format docx \
  --reference-doc template.docx

# With headers/footers from a template (combined with YAML styles)
document-agent compose input.md output.docx --format docx \
  --header-footer-doc template.docx

# Slides - polished (Marp, limited editability)
document-agent compose slides.md out.pptx --format pptx --slides

# Slides - draft editable (pandoc, fully editable, rough layout)
document-agent compose slides.md out.pptx --format pptx --slides --draft

# Slides - draft + corporate template (requires PowerPoint)
document-agent compose slides.md out.pptx --format pptx --slides --draft \
  --template corporate.pptx

YAML front matter styles

Define document formatting directly in the Markdown source. Styles are auto-extracted during digest and auto-applied during compose:

---
title: "Document Title"
subtitle: "Optional *formatted* subtitle"
styles:
  page:
    size: "A4"                    # or "Letter"
    margin-top: "1.5cm"
    margin-bottom: "1.5cm"
    margin-left: "1.5cm"
    margin-right: "1.5cm"
  body:
    font: "Calibri"
    size: 11
    spacing-before: "0.0cm"
    spacing-after: "0.1cm"
    line-spacing: 1.1
  heading1:
    font: "Calibri"
    size: 13
    bold: true
    color: "000080"               # navy
    spacing-before: "0.3cm"
    spacing-after: "0.1cm"
  heading2:
    font: "Calibri"
    size: 11
    bold: true
    color: "000080"
  heading3:
    font: "Calibri"
    size: 11
    bold: true
    color: "333333"
  table:
    size: 9                       # also used for footnotes and captions
    border-color: "999999"
    border-size: 4                # eighths of a point
    fixed: false                  # true to keep equal-width columns
---

Style priority: YAML front matter > --reference-doc > pandoc defaults.

Mermaid and draw.io diagrams in fenced code blocks are automatically rendered as images.

Diagrams

Generate and modify diagrams (Mermaid or draw.io) using LLM-powered optimization.

# Generate from description
document-agent diagram "flowchart of CI/CD pipeline" -o diagram.png

# Modify existing draw.io diagram
document-agent diagram "Change WP3 label to Digital Infrastructure" \
  --source diagram.drawio.png -o updated.drawio.png \
  --code-output updated.drawio

# Mermaid diagram
document-agent diagram "sequence diagram for auth flow" --type mermaid -o auth.png

draw.io diagrams with embedded raster images are handled automatically: images are stripped for LLM editing (reducing context from ~400 KB to ~8 KB) and restored in the output. For correct PNG rendering of embedded images, set DRAWIO_DESKTOP_PATH in .env (the npm CLI can't render inline images).

Image Generation

Generate, edit, and extract elements from raster images using text-to-image models.

Modes

  • generate: Text-to-image from a prompt, with optional style prefix
  • edit: Modify an existing image with a text prompt (inpainting with optional mask for OpenAI, img2img for Flux)
  • cut: Extract a specific element from an image (VLM-guided bounding box + background removal, falls back to image model isolation)

Supported providers

Provider Endpoint format Generate Edit Models
Azure OpenAI https://{resource}.cognitiveservices.azure.com/openai/deployments/{model} Yes Yes (mask) gpt-image-2
OpenAI https://api.openai.com Yes Yes (mask) gpt-image-2, dall-e-3
Azure AI Foundry https://{resource}.services.ai.azure.com/providers/{provider} Yes Yes (img2img) flux-2-pro, flux-2-dev
Direct provider https://api.bfl.ai Yes Yes (img2img) flux-2-pro, flux-2-dev

Configure via environment variables:

IMAGE_GEN_ENDPOINT=https://example.cognitiveservices.azure.com/openai/deployments/gpt-image-2
IMAGE_GEN_API_KEY=your-key
IMAGE_GEN_MODEL=gpt-image-2

Crossover: embedding images in diagrams

Generated images (icons, symbols) can be embedded into draw.io diagrams via the embeds parameter on generate_diagram. Refer to each embed by its filename in the diagram description so the LLM knows where to place them.

The embed mechanism reuses the existing draw.io image strip/restore pipeline: images are represented as __IMG_N__ placeholders during LLM codegen and replaced with base64 data URIs before rendering.

Forms

Inspect and fill form fields in PDF and DOCX files.

# Inspect form fields
document-agent inspect form.pdf
document-agent inspect form.docx --json

# Fill form fields
document-agent fill form.pdf filled.pdf --data '{"name": "John", "date": "2026-01-01"}'
document-agent fill form.docx filled.docx --data fields.json

Slide Merge

Cherry-pick and merge slides from multiple PPTX sources.

# Merge specific slides by index
document-agent merge-slides deck1.pptx:0-5 deck2.pptx:3,7,12 -o merged.pptx

# Use a different base template for theme/master
document-agent merge-slides deck1.pptx:0-5 deck2.pptx:3,7 \
  --base template.pptx -o merged.pptx

# Force python-pptx backend (portable, no PowerPoint needed)
document-agent merge-slides deck.pptx:0-10 -o subset.pptx --backend pptx

Backends: COM (PowerPoint, preserves animations/transitions/media) is preferred. Falls back to python-pptx (portable, pure Python) when PowerPoint is unavailable. Install optional dependencies: pip install document-agent[slides]

Setup

uv sync
cp .env.example .env
# Edit .env with your API keys and tool paths

Node.js tools (Marp, Mermaid, draw.io CLI)

Marp CLI, Mermaid CLI, and draw.io export are installed locally via npm:

cd tools && npm install

The agent automatically discovers them in tools/node_modules/.bin/.

Other external tools

  • Pandoc - DOCX digest and document composition - install system-wide
  • LibreOffice - Office format OCR fallback - install system-wide
  • draw.io desktop - needed for rendering diagrams with embedded images. Set DRAWIO_DESKTOP_PATH in .env.

Python API

from document_agent import (
    digest, compose, compose_editable_slides,
    merge_slides, parse_source_args,
    OutputFormat, OutputMode,
)

# Digest a DOCX with tracked changes
result = digest("document.docx", track_changes="all")
print(result.markdown)

# Compose with YAML styles
result = compose("styled.md", "output.docx", OutputFormat.PDF)

# Compose with reference doc
result = compose("input.md", "output.docx", OutputFormat.DOCX,
                 reference_doc="template.docx")

# Slides - polished (Marp)
result = compose("slides.md", "out.pptx", OutputFormat.PPTX,
                 is_slides=True)

# Slides - draft editable (pandoc)
result = compose("slides.md", "out.pptx", OutputFormat.PPTX,
                 is_slides=True, draft=True)

# Slides - draft + corporate template
result = compose("slides.md", "out.pptx", OutputFormat.PPTX,
                 is_slides=True, draft=True,
                 template="corporate.pptx")

# Merge slides from CLI-style args
config = parse_source_args(
    ["deck1.pptx:0-5", "deck2.pptx:3,7"],
    output="merged.pptx",
)
result = merge_slides(config, "merged.pptx")

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

semos_agentura_document-0.5.0.tar.gz (223.9 kB view details)

Uploaded Source

Built Distribution

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

semos_agentura_document-0.5.0-py3-none-any.whl (153.0 kB view details)

Uploaded Python 3

File details

Details for the file semos_agentura_document-0.5.0.tar.gz.

File metadata

  • Download URL: semos_agentura_document-0.5.0.tar.gz
  • Upload date:
  • Size: 223.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for semos_agentura_document-0.5.0.tar.gz
Algorithm Hash digest
SHA256 df853457f7316fa31c00094b9d9c4846e9dc9d6ef3c1e6ae0e9bd0434496dd46
MD5 6f3017cb0fda9d6fd0231033ae2554f6
BLAKE2b-256 af46a73ae0b2e96eb1fbe1aa3e5adcdefbd96b0d64803c032227694120690d4d

See more details on using hashes here.

File details

Details for the file semos_agentura_document-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: semos_agentura_document-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 153.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for semos_agentura_document-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa2f9fa43b722ef9b77d9454213f28444358221e021715f7cdf7c17ba8b8363f
MD5 f4a35ca06f1b2e4776db7fb11233c0ff
BLAKE2b-256 93174b01b89c0a65afce98448a3cd41fd4f743dc055eea8de1bd817c380f8a0e

See more details on using hashes here.

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