1---
2name: oma-pdf
3description: >
4 Convert PDF files to Markdown using opendataloader-pdf. Extracts text, tables, headings,
5 lists, and images with correct reading order. Use for PDF parsing, PDF to Markdown conversion,
6 document extraction, and AI-ready data preparation.
7---
8
9# PDF Skill - PDF to Markdown Conversion
10
11## Scheduling
12
13### Goal
14Convert PDF files into structured Markdown or another requested extraction format while preserving readable document structure for LLM context, RAG, or downstream review.
15
16### Intent signature
17- User asks to convert, parse, read, extract, or transform a PDF.
18- User needs PDF text, headings, lists, tables, or images prepared for AI consumption.
19- User mentions "PDF to markdown", "parse PDF", "read this PDF", or equivalent wording.
20
21### When to use
22- Converting PDF documents to Markdown for LLM context or RAG
23- Extracting structured content such as tables, headings, lists, images, footnotes, or hyperlinks
24- Preparing PDF data for AI consumption
25- Checking whether a PDF has a text layer before choosing OCR
26
27### When NOT to use
28- Generating or creating PDFs -> use document-generation tools
29- Editing existing PDFs -> out of scope
30- Reading an already-text file -> use direct file reading
31- Processing HWP, HWPX, DOCX, XLSX, or slide decks -> use the matching document skill
32
33### Expected inputs
34- `input_path`: PDF file or folder path
35- `output_dir`: optional target directory
36- `format`: optional output format, default `markdown`
37- `ocr_languages`: optional OCR language list for scanned or image-based PDFs
38- `extraction_options`: optional flags for tagged structure, image extraction, or hybrid conversion
39
40### Expected outputs
41- Markdown, text, JSON, HTML, or combined extraction output
42- Normalized Markdown when Markdown is produced
43- A short report with output path, page count, and conversion issues
44
45### Dependencies
46- `uvx opendataloader-pdf` for standard conversion
47- `uvx --from "opendataloader-pdf[hybrid]" opendataloader-pdf-hybrid` for OCR or hybrid conversion (the hybrid server is a console script of the `[hybrid]` extra, not a standalone package)
48- `uvx mdformat` for Markdown normalization
49- Local filesystem access to input and output paths
50- Optional OCR runtime via the hybrid server
51
52### Control-flow features
53- Branches on text-layer quality, tagged PDF availability, scan/OCR needs, and user-requested output format
54- Calls external CLI tools through `uvx`
55- Reads local files and writes local extraction outputs
56- Uses a hybrid server only when OCR or complex extraction needs justify it
57
58## Structural Flow
59
60### Entry
611. Confirm that the input path exists and is a PDF file, PDF folder, or supported batch input.
622. Check file size and warn when the input is large enough to risk slow conversion or memory pressure.
633. Resolve `output_dir` and the expected output filename.
64
65### Scenes
661. **PREPARE**: Validate the input path, output target, and requested extraction options.
672. **ACQUIRE**: Assess whether the PDF has a readable text layer by extracting a text preview.
683. **ACT**: Convert using standard mode, tagged-structure mode, or hybrid OCR mode.
694. **VERIFY**: Run `mdformat` for Markdown output and inspect the result for readable structure.
705. **FINALIZE**: Report output path, page count, format, and any extraction quality issues.
71
72### Transitions
73- If the preview text is readable, use standard conversion.
74- If the PDF is tagged and standard output is garbled, retry with `--use-struct-tree`.
75- If the PDF is scanned or image-based, start or reuse the hybrid OCR server and convert with hybrid mode.
76- If conversion fails because the PDF is encrypted, stop and ask for the password or an unlocked copy.
77- If conversion hits memory or size limits, process smaller page ranges or batches.
78
79### Failure and recovery
80| Failure | Recovery |
81|---------|----------|
82| `uvx` unavailable | Ask user to install `uv` before conversion |
83| `opendataloader-pdf-hybrid` not found | Invoke via `uvx --from "opendataloader-pdf[hybrid]" opendataloader-pdf-hybrid`; the bare package name does not exist on PyPI |
84| Password-protected PDF | Ask for password or unlocked PDF |
85| Garbled output | Retry with tagged structure or hybrid mode |
86| Missing tables | Retry with hybrid mode for complex or borderless tables |
87| OCR language mismatch | Retry with explicit OCR languages, for example `ko,en` |
88| Large file or memory pressure | Split into page ranges or batch smaller inputs |
89
90### Exit
91- Success: output file exists, Markdown is formatted when applicable, and extracted structure is readable.
92- Partial success: output exists but quality issues are reported explicitly.
93- Failure: no reliable output is produced and the blocking cause is reported.
94
95## Logical Operations
96
97### Actions
98| Action | SSL primitive | Evidence |
99|--------|---------------|----------|
100| Validate path and options | `VALIDATE` | Input preflight in execution protocol |
101| Probe text layer | `READ` | Text preview extraction |
102| Choose conversion strategy | `SELECT` | Standard, tagged, or hybrid mode decision |
103| Run converter | `CALL_TOOL` | `uvx opendataloader-pdf` |
104| Start OCR server | `CALL_TOOL` | `uvx --from "opendataloader-pdf[hybrid]" opendataloader-pdf-hybrid` |
105| Write output artifact | `WRITE` | Markdown, text, JSON, or HTML output |
106| Normalize Markdown | `CALL_TOOL` | `uvx mdformat` |
107| Inspect extraction quality | `VALIDATE` | Structure/readability verification |
108| Report result | `NOTIFY` | Final user-facing summary |
109
110### Tools and instruments
111- `opendataloader-pdf`: primary PDF extraction CLI
112- `opendataloader-pdf-hybrid`: hybrid OCR and complex extraction path
113- `mdformat`: Markdown normalization
114- Filesystem commands such as `file`, `wc`, or `pdfinfo` may be used for preflight when available
115
116### Canonical command path
117```bash
118uvx opendataloader-pdf "{input_path}" --format markdown --output-dir "{output_dir}"
119uvx mdformat "{output_path}"
120```
121
122For scanned/image-based PDFs, start OCR first and then convert through hybrid mode:
123```bash
124uvx --from "opendataloader-pdf[hybrid]" opendataloader-pdf-hybrid --port 5002 --force-ocr --ocr-lang "{languages}"
125uvx opendataloader-pdf --hybrid docling-fast "{input_path}" --format markdown --output-dir "{output_dir}"
126```
127
128### Resource scope
129| Scope | Resource target |
130|-------|-----------------|
131| `LOCAL_FS` | Input PDFs and generated output files |
132| `PROCESS` | `uvx` subprocesses and optional hybrid server |
133| `MEMORY` | Extracted previews and validation notes |
134| `OTHER` | OCR model/runtime behavior inside hybrid mode |
135
136### Preconditions
137- The input PDF path exists and is readable.
138- The output location is writable or can be created.
139- Required CLIs are available through `uvx`.
140- OCR is only attempted when hybrid mode is available or can be started.
141
142### Effects and side effects
143- Creates or overwrites extraction output depending on configuration and user intent.
144- May start a local hybrid OCR server on the configured port.
145- May consume significant CPU, memory, or time for large or scanned PDFs.
146- Does not intentionally modify the source PDF.
147
148### Guardrails
1491. Do not invent missing content when extraction is incomplete.
1502. Always report garbled text, missing tables, OCR uncertainty, or partial extraction.
1513. Prefer standard conversion first when the text layer is readable.
1524. Use OCR only when the PDF is scanned, image-based, or standard extraction quality is insufficient.
1535. Keep detailed command sequences in `resources/execution-protocol.md` rather than duplicating every variant here.
154
155## References
156- Execution protocol: `resources/execution-protocol.md`
157- Configuration: `config/pdf-config.yaml`
158- Context loading: `../_shared/core/context-loading.md`
159- Quality principles: `../_shared/core/quality-principles.md`