Back to API Docs
POSThttps://app.alternapdf.com/api/v1/convert/pdf-to-markdown

PDF to Markdown

Convert PDF documents into well-structured Markdown. Automatically detects headings, lists, tables, and code blocks. Supports ATX and Setext heading styles, multiple table formats, and preserves bold/italic formatting. OCR is applied automatically for scanned documents.

Content-Type: multipart/form-data

Parameters

ParameterTypeDefaultDescription
file requiredfileThe PDF file to convert to Markdown.
detect_headingsbooleantrueDetect and convert headings based on font size and weight.
detect_listsbooleantrueDetect and format bulleted and numbered lists.
detect_tablesbooleantrueDetect tabular data and convert to Markdown tables.
detect_code_blocksbooleantrueDetect code blocks based on monospace fonts and formatting.
preserve_bold_italicbooleantruePreserve bold and italic text formatting in Markdown syntax.
add_page_breaksbooleantrueInsert page break markers between pages in the output.
include_metadatabooleanfalseInclude PDF metadata as YAML front matter in the Markdown output.
heading_stylestringatxHeading format. atx uses # Heading syntax, setext uses underline syntax.
table_formatstringpipeTable output format. Options: pipe, grid, simple.

Code Examples

cURL
curl -X POST "https://app.alternapdf.com/api/v1/convert/pdf-to-markdown" \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "file=@document.pdf" \
  -F "detect_headings=true" \
  -F "detect_tables=true" \
  -F "detect_code_blocks=true" \
  -F "heading_style=atx" \
  -F "table_format=pipe"
Python
import requests

url = "https://app.alternapdf.com/api/v1/convert/pdf-to-markdown"
headers = {"X-API-Key": "YOUR_API_KEY"}

with open("document.pdf", "rb") as f:
    files = {"file": ("document.pdf", f, "application/pdf")}
    data = {
        "detect_headings": "true",
        "detect_tables": "true",
        "detect_code_blocks": "true",
        "heading_style": "atx",
        "table_format": "pipe",
    }
    response = requests.post(url, headers=headers, files=files, data=data)

result = response.json()
markdown = result["data"]["markdown"]

# Save to file
with open("output.md", "w") as out:
    out.write(markdown)

print(f"Pages: {result['data']['total_pages']}")
print(f"Processing time: {result['data']['processing_time_ms']}ms")
JavaScript
const formData = new FormData();
formData.append("file", fs.createReadStream("document.pdf"));
formData.append("detect_headings", "true");
formData.append("detect_tables", "true");
formData.append("detect_code_blocks", "true");
formData.append("heading_style", "atx");
formData.append("table_format", "pipe");

const response = await fetch("https://app.alternapdf.com/api/v1/convert/pdf-to-markdown", {
  method: "POST",
  headers: {
    "X-API-Key": "YOUR_API_KEY",
  },
  body: formData,
});

const result = await response.json();
const { markdown, total_pages, processing_time_ms } = result.data;

console.log(markdown);
console.log(`Pages: ${total_pages}, Time: ${processing_time_ms}ms`);

Response

Returns a JSON object containing the converted Markdown and processing metadata.

JSON Response
{
  "status": "success",
  "data": {
    "markdown": "# Document Title\n\nThis is the first paragraph of content...\n\n## Section One\n\n| Column A | Column B |\n|----------|----------|\n| Value 1  | Value 2  |\n\n---\n\n*Page 2 content...*",
    "total_pages": 5,
    "processing_time_ms": 1245,
    "ocr_used": false,
    "ocr_engine": null,
    "ocr_confidence": null,
    "cost_usd": 0.005
  }
}
FieldTypeDescription
statusstringProcessing status. Always success on 200.
data.markdownstringThe converted Markdown content.
data.total_pagesintegerNumber of pages processed.
data.processing_time_msintegerProcessing time in milliseconds.
data.ocr_usedbooleanWhether OCR was applied to any pages.
data.ocr_enginestring | nullOCR engine used, or null if not applicable.
data.ocr_confidencenumber | nullOCR confidence score (0-1), or null if not applicable.
data.cost_usdnumberCost of this request in USD.