PaddleOCR Document Parsing
When to Use This Skill
Use this skill for:
- Documents with tables (invoices, financial reports, spreadsheets)
- Documents with mathematical formulas (academic papers, scientific documents)
- Documents with charts and diagrams
- Multi-column layouts (newspapers, magazines, brochures)
- Complex document structures requiring layout analysis
- Converting PDFs to structured Markdown with images
Usage
Method 1: Python API (Recommended)
import json, os, requests, sys, time
JOB_URL = "https://paddleocr.aistudio-app.com/api/v2/ocr/jobs"
TOKEN = os.environ.get("PADDLEOCR_ACCESS_TOKEN")
MODEL = "PaddleOCR-VL-1.6"
file_path = "<local file path or file url>"
headers = {"Authorization": f"bearer {TOKEN}"}
optional_payload = {
"useDocOrientationClassify": True,
"useDocUnwarping": True,
"useChartRecognition": True,
}
# For URL input:
headers["Content-Type"] = "application/json"
payload = {"fileUrl": file_url, "model": MODEL, "optionalPayload": optional_payload}
job_response = requests.post(JOB_URL, json=payload, headers=headers)
# For local file input:
data = {"model": MODEL, "optionalPayload": json.dumps(optional_payload)}
with open(file_path, "rb") as f:
job_response = requests.post(JOB_URL, headers=headers, data=data, files={"file": f})
assert job_response.status_code == 200
jobId = job_response.json()["data"]["jobId"]
# Poll for results:
while True:
result = requests.get(f"{JOB_URL}/{jobId}", headers=headers).json()["data"]
state = result["state"]
if state == "done":
jsonl_url = result["resultUrl"]["jsonUrl"]
break
elif state == "failed":
print(f"Job failed: {result['errorMsg']}")
sys.exit()
time.sleep(5)
# Parse results and save:
lines = requests.get(jsonl_url).text.strip().split('\n')
output_dir = "output"
os.makedirs(output_dir, exist_ok=True)
page_num = 0
for line in lines:
result = json.loads(line)["result"]
for res in result["layoutParsingResults"]:
# Save markdown
md_filename = os.path.join(output_dir, f"doc_{page_num}.md")
with open(md_filename, "w", encoding="utf-8") as md_file:
md_file.write(res["markdown"]["text"])
# Download images
for img_path, img in res["markdown"]["images"].items():
full_img_path = os.path.join(output_dir, img_path)
os.makedirs(os.path.dirname(full_img_path), exist_ok=True)
with open(full_img_path, "wb") as img_file:
img_file.write(requests.get(img).content)
# Download output images (layout visualization, etc.)
for img_name, img in res["outputImages"].items():
img_response = requests.get(img)
if img_response.status_code == 200:
filename = os.path.join(output_dir, f"{img_name}_{page_num}.jpg")
with open(filename, "wb") as f:
f.write(img_response.content)
page_num += 1
Method 2: CLI
paddleocr api \
--model_type doc_parsing \
--file_path "./document.pdf"
Important Notes
- For doc parsing, keep preprocessing enabled (useDocOrientationClassify, useDocUnwarping) by default
- Only disable preprocessing for flat, well-oriented scans where speed matters
useChartRecognition: True enables chart/diagram extraction
- Output includes: Markdown text, inline images, layout visualization images
- Always display full extracted content, don't truncate unless exceeding 10,000 chars
- Handle errors gracefully: auth issues, rate limits, blank documents
1---2name: paddleocr-doc-parsing3description: Use this skill to extract structured Markdown/JSON from PDFs and document images—tables with cell-level precision, formulas as LaTeX, figures, seals, charts, headers/footers, multi-column layout and correct reading order. Trigger terms: 文档解析, 版面分析, 版面还原, 表格提取, 公式识别, 多栏排版, 扫描件结构化, 发票, 财报, 复杂 PDF, PDF转Markdown, 图表, 阅读顺序; reading order, formula, LaTeX, layout parsing, structure extraction, PP-StructureV3, PaddleOCR-VL.4license: Apache-2.05---67# PaddleOCR Document Parsing89## When to Use This Skill1011**Use this skill for**:1213- Documents with tables (invoices, financial reports, spreadsheets)14- Documents with mathematical formulas (academic papers, scientific documents)15- Documents with charts and diagrams16- Multi-column layouts (newspapers, magazines, brochures)17- Complex document structures requiring layout analysis18- Converting PDFs to structured Markdown with images1920## Usage2122### Method 1: Python API (Recommended)2324```python25import json, os, requests, sys, time2627JOB_URL = "https://paddleocr.aistudio-app.com/api/v2/ocr/jobs"28TOKEN = os.environ.get("PADDLEOCR_ACCESS_TOKEN")29MODEL = "PaddleOCR-VL-1.6"3031file_path = "<local file path or file url>"3233headers = {"Authorization": f"bearer {TOKEN}"}3435optional_payload = {36 "useDocOrientationClassify": True,37 "useDocUnwarping": True,38 "useChartRecognition": True,39}4041# For URL input:42headers["Content-Type"] = "application/json"43payload = {"fileUrl": file_url, "model": MODEL, "optionalPayload": optional_payload}44job_response = requests.post(JOB_URL, json=payload, headers=headers)4546# For local file input:47data = {"model": MODEL, "optionalPayload": json.dumps(optional_payload)}48with open(file_path, "rb") as f:49 job_response = requests.post(JOB_URL, headers=headers, data=data, files={"file": f})5051assert job_response.status_code == 20052jobId = job_response.json()["data"]["jobId"]5354# Poll for results:55while True:56 result = requests.get(f"{JOB_URL}/{jobId}", headers=headers).json()["data"]57 state = result["state"]58 if state == "done":59 jsonl_url = result["resultUrl"]["jsonUrl"]60 break61 elif state == "failed":62 print(f"Job failed: {result['errorMsg']}")63 sys.exit()64 time.sleep(5)6566# Parse results and save:67lines = requests.get(jsonl_url).text.strip().split('\n')68output_dir = "output"69os.makedirs(output_dir, exist_ok=True)70page_num = 071for line in lines:72 result = json.loads(line)["result"]73 for res in result["layoutParsingResults"]:74 # Save markdown75 md_filename = os.path.join(output_dir, f"doc_{page_num}.md")76 with open(md_filename, "w", encoding="utf-8") as md_file:77 md_file.write(res["markdown"]["text"])78 # Download images79 for img_path, img in res["markdown"]["images"].items():80 full_img_path = os.path.join(output_dir, img_path)81 os.makedirs(os.path.dirname(full_img_path), exist_ok=True)82 with open(full_img_path, "wb") as img_file:83 img_file.write(requests.get(img).content)84 # Download output images (layout visualization, etc.)85 for img_name, img in res["outputImages"].items():86 img_response = requests.get(img)87 if img_response.status_code == 200:88 filename = os.path.join(output_dir, f"{img_name}_{page_num}.jpg")89 with open(filename, "wb") as f:90 f.write(img_response.content)91 page_num += 192```9394### Method 2: CLI9596```bash97paddleocr api \98 --model_type doc_parsing \99 --file_path "./document.pdf"100```101102## Important Notes103104- For doc parsing, keep preprocessing enabled (useDocOrientationClassify, useDocUnwarping) by default105- Only disable preprocessing for flat, well-oriented scans where speed matters106- `useChartRecognition: True` enables chart/diagram extraction107- Output includes: Markdown text, inline images, layout visualization images108- Always display full extracted content, don't truncate unless exceeding 10,000 chars109- Handle errors gracefully: auth issues, rate limits, blank documents