Skip to main content

Convert PDF, DOCX, PPTX, Medium, Wikipedia and CSV documents to Markdown. Extracts text, images, and tables. Supports LLM-based extraction.

Project description

Doctomarkdown Logo

Doctomarkdown


Doctomarkdown

Doctomarkdown is a robust Python library for converting documents—including PDF, DOCX, PPTX, and CSV—into clean, readable Markdown. It supports extracting text, images, and tables, and is easily extensible for more document types. Advanced extraction is available via LLM (Large Language Model) clients.


Features

  • 📄 Convert PDF, DOCX, PPTX, and CSV to Markdown
  • 🖼️ Extract images from documents (optional)
  • 📊 Extract tables from documents (optional)
  • 🤖 LLM support : Supports AzureOpenAI, Groq, Gemini, OpenAI, Ollama
  • 🗂️ Extensible: Add support for more document types
  • 🏷️ Custom output directory

Installation

$ pip install doctomarkdown

Note: Requires Python 3.10+


Usage Examples

1. Convert PDF to Markdown (No LLM)

from doctomarkdown import DocToMarkdown

app = DocToMarkdown()

result = app.convert_pdf_to_markdown(
    filepath="sample_docs/Non-text-searchable.pdf",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

2. Convert PDF to Markdown using Groq LLM Client

from groq import Groq
from doctomarkdown import DocToMarkdown
from dotenv import load_dotenv
import os
load_dotenv()

client_groq = Groq(
    api_key=os.environ.get("GROQ_API_KEY"),
)

app = DocToMarkdown(
    llm_client=client_groq,
    llm_model='meta-llama/llama-4-scout-17b-16e-instruct'
)

result = app.convert_pdf_to_markdown(
    filepath="sample_docs/Non-text-searchable.pdf",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

3. Convert PDF to Markdown using Gemini LLM Client

from google import genai
from dotenv import load_dotenv
import os
load_dotenv()
import google.generativeai as genai
from doctomarkdown import DocToMarkdown

genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
vision_model = genai.GenerativeModel("gemini-1.5-flash")  # Choose your Gemini Vision model

app = DocToMarkdown(
    llm_client=vision_model
)

result = app.convert_pdf_to_markdown(
    filepath="sample_docs/Non-text-searchable.pdf",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

4. Convert PDF to Markdown using Azure OpenAI Client

from doctomarkdown import DocToMarkdown
from openai import AzureOpenAI
from dotenv import load_dotenv
import os
load_dotenv()

client = AzureOpenAI(
    api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
    azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
    api_version=os.environ.get("AZURE_OPENAI_API_VERSION"),
)

app = DocToMarkdown(
    llm_client=client,
    llm_model='gpt-4o'
)

result = app.convert_pdf_to_markdown(
    filepath="sample_docs/Non-text-searchable.pdf",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

5. Convert PDF to Markdown using Ollama API Client

from doctomarkdown import DocToMarkdown
from openai import OpenAI

ollama_client = OpenAI(
    base_url = 'http://localhost:11434/v1',
    api_key='ollama',
)

app = DocToMarkdown(llm_client=ollama_client, llm_model='gemma3:4b')
result = app.convert_pdf_to_markdown(
    filepath="sample_docs/Non-text-searchable.pdf",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

6. Convert PDF to Markdown using OpenAI LLM Client

from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
)

app = DocToMarkdown(llm_client=client, 
                    llm_model='gpt-4o')

result = app.convert_pdf_to_markdown(
    filepath="sample_docs/sample-1.pdf",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

6. Convert DOCX to Markdown

from doctomarkdown import DocToMarkdown
from dotenv import load_dotenv
load_dotenv()

from groq import Groq


client_groq = Groq(
    # api_key=os.environ.get("GROQ_API_KEY")
)

app = DocToMarkdown(llm_client=client_groq, 
                    llm_model='llama3-8b-8192')

result = app.convert_docx_to_markdown(
    filepath="sample_docs/Sampledoc-1.docx",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

7. Convert PPTX to Markdown

from doctomarkdown import DocToMarkdown
from dotenv import load_dotenv
load_dotenv()

app = DocToMarkdown()

result = app.convert_pptx_to_markdown(
    filepath="sample_docs/sample-ppt-1.pptx",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

for page in result.pages:
    print(f"Page Number: {page.page_number} | Page Content: {page.page_content}")

8. Convert CSV to Markdown

from doctomarkdown import DocToMarkdown

app = DocToMarkdown()

result = app.convert_csv_to_markdown(
    filepath="sample_docs/sample.csv",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

8. Convert URL to Markdown

from doctomarkdown import DocToMarkdown
from dotenv import load_dotenv
load_dotenv()

app = DocToMarkdown()

# Convert Medium article
result = app.convert_url_to_markdown(
    urlpath="https://medium.com/the-ai-forum/build-a-local-reliable-rag-agent-using-crewai-and-groq-013e5d557bcd",
    extract_images=True,
    extract_tables=True,
    output_path="markdown_output"
)

# Display first 500 chars to preview
for page in result.pages:
    print(f"Page Number: {page.page_number}")
    print(f"Content Preview: {page.page_content[:500]}...")
    print(f"Total Length: {len(page.page_content)} characters")

License

This project is licensed under the MIT License.

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

doctomarkdown-0.1.7.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.

doctomarkdown-0.1.7-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file doctomarkdown-0.1.7.tar.gz.

File metadata

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

File hashes

Hashes for doctomarkdown-0.1.7.tar.gz
Algorithm Hash digest
SHA256 e3aaf95ba062843e3f4c02e1d5fb17e1a065fcd7bc8d4e04b60ce6b18f88e61a
MD5 6618e52c706ef3613de9ade536613eff
BLAKE2b-256 baf742e99fac137d6e92ee9b1fa6fb2a42ae95b2bf4e334e0bfeb61663e038f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for doctomarkdown-0.1.7.tar.gz:

Publisher: publish-to-pypi.yml on DocParseAI/doctomarkdown

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

File details

Details for the file doctomarkdown-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: doctomarkdown-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for doctomarkdown-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 abb6665b9d94834e2a72d650d66b141e170578f068f56b37c889cca1456bde30
MD5 b3753b591c71df3779220a542b478ee6
BLAKE2b-256 fff144bcf61df52b2fd3031e0e5ad1ba3f7818420e79ab235627ab211754387a

See more details on using hashes here.

Provenance

The following attestation bundles were made for doctomarkdown-0.1.7-py3-none-any.whl:

Publisher: publish-to-pypi.yml on DocParseAI/doctomarkdown

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