Extract Markdown
The Data Extraction API converts a document into a Markdown string when you set output.format to markdown.
Use Markdown for retrieval-augmented generation (RAG), search indexing, and content migration when you don’t need spatial element data.
For code samples and an interactive demo, refer to the PDF-to-Markdown API overview page.
Basic Markdown extraction
Send a document to /extraction/parse with output.format set to markdown, as shown in these examples:
curl -X POST https://api.nutrient.io/extraction/parse \ -H "Authorization: Bearer your_api_key_goes_here" \ -F "file=@document.pdf" \ -F 'instructions={"mode":"text","output":{"format":"markdown"}}'import requests
response = requests.post( "https://api.nutrient.io/extraction/parse", headers={"Authorization": "Bearer your_api_key_goes_here"}, files={"file": open("document.pdf", "rb")}, data={ "instructions": '{"mode":"text","output":{"format":"markdown"}}' },)
result = response.json()print(result["output"]["markdown"])import fs from "node:fs";
const form = new FormData();form.append("file", await fs.openAsBlob("document.pdf"), "document.pdf");form.append( "instructions", JSON.stringify({ mode: "text", output: { format: "markdown" } }),);
const response = await fetch("https://api.nutrient.io/extraction/parse", { method: "POST", headers: { Authorization: "Bearer your_api_key_goes_here" }, body: form,});
const result = await response.json();console.log(result.output.markdown);The JavaScript samples use fs.openAsBlob, which requires Node 19.8 or later.
Response format
The API returns the Markdown output in output.markdown as a single string:
{ "status": 200, "requestId": "req_a1b2c3d4", "output": { "markdown": "# Document Title\n\nFirst paragraph of text...\n\n## Section Two\n\nMore content here..." }, "metrics": { "processingTimeMs": 312, "pagesProcessed": 1 }, "usage": { "global_usd": { "cost": "0.00118", "currency": "USD", "includedBalance": "72.40", "walletBalance": "0.00" } }, "configuration": { "mode": "text", "outputFormat": "markdown" }}Markdown represents document structure through headings, paragraphs, lists, tables, and code blocks. When the engine decodes QR codes or barcodes, it includes their decoded values as text.
Read Markdown from the response
Use this helper to read Markdown from the response. It reads output.markdown from JSON responses or returns the response text for plain-text Markdown.
If the response omits Content-Type, the helper tries JSON parsing before returning the response text:
import json
def parse_markdown_response(response): content_type = response.headers.get("Content-Type", "")
if "application/json" in content_type: payload = response.json() return payload.get("output", {}).get("markdown", "")
if "text/plain" in content_type or "text/markdown" in content_type: return response.text
# Fallback for clients or proxies that omit Content-Type. try: payload = json.loads(response.text) except json.JSONDecodeError: return response.text
return payload.get("output", {}).get("markdown", "")Extract Markdown from a URL
To extract Markdown from a public document URL, send a JSON request with the url field:
curl -X POST https://api.nutrient.io/extraction/parse \ -H "Authorization: Bearer your_api_key_goes_here" \ -H "Content-Type: application/json" \ -d '{ "url": "https://storage.example.com/report.pdf", "mode": "text", "output": { "format": "markdown" } }'import requests
response = requests.post( "https://api.nutrient.io/extraction/parse", headers={ "Authorization": "Bearer your_api_key_goes_here", "Content-Type": "application/json", }, json={ "url": "https://storage.example.com/report.pdf", "mode": "text", "output": {"format": "markdown"}, },)
result = response.json()print(result["output"]["markdown"])const response = await fetch("https://api.nutrient.io/extraction/parse", { method: "POST", headers: { Authorization: "Bearer your_api_key_goes_here", "Content-Type": "application/json", }, body: JSON.stringify({ url: "https://storage.example.com/report.pdf", mode: "text", output: { format: "markdown" }, }),});
const result = await response.json();console.log(result.output.markdown);Choose Markdown or spatial output
Choose the output format based on the data your application needs:
| Use case | Recommended format |
|---|---|
| RAG/large language model (LLM) ingestion | Markdown |
| Search indexing | Markdown |
| Content migration | Markdown |
| Document analysis with spatial data | Spatial |
| Table extraction with cell coordinates | Spatial |
| Form layout and checkbox states | Spatial |
| Building document viewers or overlays | Spatial |
Each request returns either Markdown or spatial elements, not both. To get both formats, send two separate requests.
To return named field values, such as form fields or invoice totals, use the extract endpoint with a schema instead of either parse output.
Choose a processing mode
The examples on this page use text mode, which costs $0.001 per page. All modes support Markdown output.
Choose a mode based on your document’s layout and extraction requirements:
| Mode | Cost per page | Best for |
|---|---|---|
auto | $0.0015–$0.018 | Mixed document types; routes each page to structure, understand, or agentic |
text | $0.001 | Born-digital documents with simple layouts |
structure | $0.0015 | Scanned documents requiring optical character recognition (OCR) |
understand | $0.009 | Complex tables, charts, formulas, and multicolumn layouts |
agentic | $0.018 | The most complex documents needing vision language model (VLM) augmentation |
Set mode to understand to extract Markdown from a document with a complex layout:
curl -X POST https://api.nutrient.io/extraction/parse \ -H "Authorization: Bearer your_api_key_goes_here" \ -F "file=@document.pdf" \ -F 'instructions={"mode":"understand","output":{"format":"markdown"}}'Refer to the processing modes guide for a comparison.
Spreadsheets
For XLSX spreadsheets, the API starts each visible sheet with a level-one heading containing the sheet name. It converts titles above tables into level-two headings.
For every input type, the API outputs tables as HTML by default. These tables preserve <th> header cells and row and column spans.
The following example shows Markdown output for a sheet named Q3 sales with these contents:
- A sentence in A1.
- A merged bold title in A3:C3.
- A table in A4:C7.
# Q3 sales
All amounts in USD thousands. Figures are unaudited.
## Q3 2026 regional sales
<table> <tr><th>Region</th><th>Orders</th><th>Revenue</th></tr> <tr><td>North</td><td>412</td><td>1284.5</td></tr> <tr><td>South</td><td></td><td>978.0</td></tr> <tr><td>East</td><td>388</td><td>1102.3</td></tr></table>Refer to the spreadsheets guide for details.