Convert PDF to Markdown

Convert PDF to Markdown

Makes the AI convert PDF files to Markdown with a bundled script before reading, summarising or extracting data, including whole folders of documents.

Skill files4 files

references/

scripts/

SKILL.md131 lines
1
---
2
name: convert-pdf-to-md
3
description: 'Converts PDF (.pdf) documents into Markdown so their contents can be accurately analyzed, summarized, searched, or extracted from. Use this skill whenever the user shares, references, or asks about a .pdf file — even if they don''t say "convert" or "markdown" explicitly. This includes requests to "read", "summarize", "review", "extract data from", "compare", or "analyze" a PDF report, paper, invoice, form, contract, or scanned document. Always run the bundled conversion script to produce Markdown first; do not attempt to parse PDF content directly or write ad-hoc extraction code. Also use this skill for batch requests involving a whole folder of PDF documents. IMPORTANT: When the user references a folder or set of documents containing multiple file types (.pdf, .docx, .xlsx), invoke ALL three sibling skills — convert-pdf-to-md, convert-word-to-md, and convert-excel-to-md — so no file type is silently skipped.'
4
---
5
6
# Convert PDF to Markdown
7
8
## When to use this skill
9
10
Trigger this skill any time there is a `.pdf` file that needs to be
11
understood or processed — for example, a user attaches a PDF and asks
12
questions about it, wants a summary, wants specific data or tables pulled
13
out, or wants multiple PDFs in a folder processed together. PDF is a
14
layout/print format, not reliably readable as plain text, so always convert
15
it to Markdown first using the script in this skill rather than trying to
16
open or parse the file directly.
17
18
This skill only supports `.pdf` — that's MarkItDown's only PDF-family
19
format, so there's no legacy format to worry about here (unlike Word's
20
`.doc` or Excel's `.xls`).
21
22
**Mixed file types:** When the user references a folder or set of documents
23
containing multiple supported file types (`.pdf`, `.docx`, `.xlsx`), this
24
skill handles only `.pdf` files. The agent MUST also invoke the sibling
25
skills in parallel:
26
- `convert-word-to-md` for any `.docx` files
27
- `convert-excel-to-md` for any `.xlsx` files
28
29
Never process a folder and silently skip a supported file type. All three
30
skills must be invoked together when mixed types are present.
31
32
## Setup (once per environment)
33
34
Before the first conversion in a given environment, follow
35
[`references/setup.md`](references/setup.md) step by step to ensure Python,
36
pip, `markitdown`, and `pymupdf` (for image extraction) are installed. Do
37
this proactively rather than guessing whether the environment is ready — the
38
script itself will also fail with a clear pointer back to that file if a
39
dependency turns out to be missing, so it's safe to just try the conversion
40
first if you're reasonably confident setup was already done.
41
42
## Usage
43
44
The conversion script lives at `scripts/convert_pdf_to_md.py`.
45
46
**Output structure:** MarkItDown's PDF converter extracts text and tables
47
only — it has no concept of embedded images at all. This script separately
48
extracts real embedded images via PyMuPDF and writes a self-contained folder
49
per document:
50
51
```
52
<name>/
53
img/
54
page001_img001.<ext>
55
page002_img001.<ext>
56
...
57
<name>.md
58
```
59
60
Because MarkItDown's PDF text does not preserve reliable per-page markers,
61
there's no safe way to know exactly where inline an image belongs. Rather
62
than risk misplacing images next to the wrong paragraph, the script appends
63
a `## Extracted Images` section at the end of the Markdown, with a
64
`### Page N` subheading per page that has images — read this section
65
separately from the main body text. If the document has no embedded images,
66
no `img/` folder or `Extracted Images` section is created.
67
68
**Single file:**
69
70
```powershell
71
python scripts\convert_pdf_to_md.py "C:\path\to\document.pdf"
72
```
73
74
This creates a `document\` folder next to the source file (containing
75
`document.md` and, if present, `document\img\`). To control the destination
76
folder explicitly:
77
78
```powershell
79
python scripts\convert_pdf_to_md.py "C:\path\to\document.pdf" -o "C:\path\to\output_folder"
80
```
81
82
**A folder of PDFs (batch mode):**
83
84
```powershell
85
python scripts\convert_pdf_to_md.py "C:\path\to\folder"
86
```
87
88
Add `--recursive` to also include subfolders:
89
90
```powershell
91
python scripts\convert_pdf_to_md.py "C:\path\to\folder" --recursive
92
```
93
94
Each `.pdf` found gets its own `<name>\` output folder next to it by
95
default. Pass `-o "C:\path\to\output_parent"` to collect all the generated
96
`<name>\` folders under a separate parent directory instead (subfolder
97
structure is preserved when combined with `--recursive`).
98
99
After conversion, read the resulting `.md` file(s) to perform the actual
100
analysis the user asked for — the script's job is only to produce accurate
101
Markdown (and images), not to interpret the content.
102
103
## Deciding where output goes
104
105
**Default — always output next to the source file.** The `<name>/` folder
106
is created in the same directory as the source `.pdf`. This is the required
107
default for every case. Do NOT override it unless the user explicitly asks
108
for a different location.
109
110
**Only use `-o` when** the user explicitly provides an output path (e.g.,
111
"save the output to `C:\output`", "put the results in `D:\work`"). Do NOT
112
pass `-o` based on the agent's current working directory, the session state
113
folder, or any implied location.
114
115
**If the source file path cannot be fully resolved** — for example, the
116
user provides only a filename with no directory, or the path is ambiguous —
117
use `ask_user` to confirm the full absolute path before running the
118
conversion. Never guess or assume the directory.
119
120
## Troubleshooting
121
122
| Symptom | Likely cause | Fix |
123
|---|---|---|
124
| `ModuleNotFoundError: No module named 'markitdown'` or `'fitz'` / exit code 2 | MarkItDown or PyMuPDF not installed | Follow `references/setup.md` |
125
| `ERROR: Unsupported file type '...'` / exit code 3 | Not a `.pdf` file | Ask the user for the correct file, or if it's `.doc`/`.docx`/`.xlsx`, use the matching sibling skill instead |
126
| `ERROR: Input path not found` / exit code 3 | Wrong path, or file moved | Confirm the correct path with the user |
127
| `FAILED <file> -> ...` in batch output | That specific file is corrupt, password-protected, or otherwise unreadable | Report which file(s) failed; other files in the batch still succeed |
128
| `NOTE: skipped N non-.pdf file(s)` | Folder contains non-PDF files | Expected — those files are intentionally ignored |
129
| Markdown body is empty or near-empty despite images being extracted | The PDF is scanned/image-only with no embedded text layer; MarkItDown does not perform OCR | Tell the user OCR isn't supported — the extracted page images are still available for them to view |
130
| Images appear in an appendix instead of inline with the text | Deliberate limitation — MarkItDown's PDF text has no reliable per-page markers to place images inline | Expected behavior; cross-reference the `### Page N` heading with the surrounding text context if needed |
131

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 11,973 prompts

More by @OpenSourceBuffGuy

See all
Dataverse Python Error Handling prompt image

Dataverse Python Error Handling

Teaches the coding agent how to handle errors and troubleshoot with the Dataverse SDK for Python, including auth, throttling and transient failures.

rule-file, best-practices, debugging, troubleshooting, python, api, authentication, performance-optimization, code, for-developers, cheat-sheet, power-apps, microsoft-365, advanced, long-form, observability, conditional-logic, dataverse

A/B Test Analysis prompt image

A/B Test Analysis

Teaches an AI agent to design and analyse A/B tests in Python, covering sample size, significance testing, effect size and interpreting results.

agent-skill, ab-testing, statistics, data-analysis, data-science, python, pandas, numpy, jupyter, estimation, data-visualization, marketing, for-data-analysts, for-marketers, for-product-managers, code, step-by-step-guide, advanced, long-form, report

Paris Shopfront Editorial Portrait prompt image

Paris Shopfront Editorial Portrait

Generates a moody film-scanned editorial portrait of a young woman in an oversized leather coat outside a vintage Paris wine shop at dusk.

image-prompt, nano-banana, negative-prompt, portrait, woman, medium-shot, editorial, fashion, film-grain, muted-colors, cinematic, photorealistic, vertical-format, text-rendering, soft-lighting, moody, bokeh, cityscape

Reviews

Loading reviews…

Discussion

Loading comments…