Parse local PDF documents into structured Markdown or JSON, preserving heading hierarchy, tables, lists, and other structures. Runs on CPU, data never leaves the local machine.
Use Cases
- User says "Help me convert this PDF to Markdown" or "Extract the content of this PDF"
- Need to extract structured text from a PDF for subsequent analysis
- Scanned PDFs need OCR to extract text (works with OCR-type Skills)
- Batch process multiple PDF files
Differences from Other PDF Processing Skills
| Tool | Good At | Limitations |
|---|---|---|
| nano-pdf | Simple text extraction, PDF metadata | Does not preserve structure |
| pdf-toolkit | Merge/split/encrypt/watermark | Does not parse content |
| mineru-pdf | Structured parsing (headings/tables/lists) | Installation package is relatively large |
Prefer using mineru-pdf for content extraction and pdf-toolkit for file operations.
Execution Method
Installation
pip install magic-pdf
Basic Usage
magic-pdf -p /path/to/document.pdf -o /path/to/output/ -m auto
Parameter Description:
-p: Input PDF path-o: Output directory-m: Mode selectionauto: Automatic detection (recommended)txt: Text-only PDFocr: Scanned PDF
Python API
from magic_pdf.data.data_reader_writer import FileBasedDataWriter, FileBasedDataReader
from magic_pdf.pipe.UNIPipe import UNIPipe
reader = FileBasedDataReader("")
writer = FileBasedDataWriter(output_dir)
pdf_bytes = reader.read(pdf_path)
pipe = UNIPipe(pdf_bytes, model_list=[], image_writer=writer)
pipe.pipe_classify()
pipe.pipe_analyze()
pipe.pipe_parse()
md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
Output Content
After parsing, the following are generated in the output directory:
*.md: Structured content in Markdown formatimages/: Extracted images*.json: Structured metadata
Output Specifications
- Preserve the original document's heading hierarchy (H1-H6)
- Convert tables to Markdown tables
- Extract images and reference them with
reference - Page numbers are marked at the end of each section