Metadata-Version: 2.4
Name: doctomarkdown
Version: 0.1.9
Summary: Convert PDF, DOCX, PPTX, Medium, Wikipedia and CSV documents to Markdown. Extracts text, images, and tables. Supports LLM-based extraction.
Home-page: https://github.com/DocParseAI/doctomarkdown
Author: docparseai
Author-email: docparseai <sayantanghosh.work@gmail.com>
License: MIT License
        
        Copyright (c) 2025 DocParseAI
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/DocParseAI/doctomarkdown
Project-URL: Documentation, https://github.com/DocParseAI/doctomarkdown#readme
Project-URL: BugTracker, https://github.com/DocParseAI/doctomarkdown/issues
Project-URL: PyPI, https://pypi.org/project/doctomarkdown/
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyMuPDF
Requires-Dist: Pillow
Requires-Dist: typing-extensions
Requires-Dist: python-docx
Requires-Dist: python-pptx
Requires-Dist: pandas
Requires-Dist: tabulate
Requires-Dist: html2text
Requires-Dist: beautifulsoup4
Requires-Dist: google-generativeai
Requires-Dist: pytesseract
Requires-Dist: comtypes
Requires-Dist: docx2pdf
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

<!-- Logo and Title -->
<p align="center">
  <img src="https://img.icons8.com/ios-filled/100/000000/markdown.png" alt="Doctomarkdown Logo" width="100"/>
</p>

<h1 align="center">Doctomarkdown</h1>

![PyPI - Install - Static](https://img.shields.io/badge/pip_install-doctomarkdown-blue)
![PyPI - Version](https://img.shields.io/pypi/v/doctomarkdown.svg)
![PyPI - Downloads](https://img.shields.io/pypi/dm/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

```bash
$ pip install doctomarkdown
```

> **Note:** Requires Python 3.10+

---

## Usage Examples

### 1. Convert PDF to Markdown (No LLM)

```python
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",
    output_type="markdown"  # or 'text' for .txt 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

```python
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",
    output_type="markdown"  # or 'text' for .txt 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

```python
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",
    output_type="markdown"  # or 'text' for .txt 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

```python
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",
    output_type="markdown"  # or 'text' for .txt 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

```python
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",
    output_type="markdown"  # or 'text' for .txt 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

```python
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",
    output_type="markdown"  # or 'text' for .txt output
)

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

```
---

### 6. Convert DOCX to Markdown

```python
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",
    output_type="markdown"  # or 'text' for .txt output
)

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

---

### 7. Convert PPTX to Markdown

```python
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",
    output_type="markdown"  # or 'text' for .txt output
)

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

---

### 8. Convert CSV to Markdown

```python
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",
    output_type="markdown"  # or 'text' for .txt output
)
```

### 8. Convert URL to Markdown

```python
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",
    output_type="markdown"  # or 'text' for .txt 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.
