# `render_document_pdf` — Render Markdown or HTML Document to Themed PDF

> Part of [PDF Forge & Layout Diagnostics Edge API](https://pdf-forge.apikeg.com/llms.txt) (`com.apikeg/pdf-forge`)

Compiles Markdown (headings, bold/italic/code, lists, GFM tables, callouts, '---pagebreak---') or HTML into both print-ready themed HTML and a spec-compliant multi-page PDF 1.7 binary with running headers, 'Page X of Y' footers, repeated table headers across page breaks, optional watermark, and deterministic layoutDiagnostics.

**Why call instead of DIY:** Avoids spinning up 400MB Puppeteer/Playwright containers or hand-rolling brittle PDF stream/xref math; returns both binary PDF and layout QA diagnostics in <20ms at $0.004.

- **REST Endpoint:** `POST https://pdf-forge.apikeg.com/v1/render-document-pdf`
- **MCP Server:** `https://pdf-forge.apikeg.com/mcp` (tool: `render_document_pdf`)
- **Pricing:** $0.004 USD per rendered PDF document (x402 instant micropayment)
- **Free Dry-Run:** `POST https://pdf-forge.apikeg.com/v1/render-document-pdf?dry_run=true`

## Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "content": {
      "type": "string",
      "minLength": 1,
      "maxLength": 524288,
      "description": "Markdown (headings, bold/italic/code, lists, GFM tables, callouts, '---pagebreak---') or raw HTML body to compile."
    },
    "contentFormat": {
      "type": "string",
      "enum": [
        "markdown",
        "html"
      ],
      "default": "markdown",
      "description": "Input syntax format ('markdown' or 'html')."
    },
    "title": {
      "type": "string",
      "maxLength": 240,
      "description": "Optional document title rendered in the cover banner and stored in PDF /Title metadata."
    },
    "subtitle": {
      "type": "string",
      "maxLength": 320,
      "description": "Optional subtitle rendered below the title and stored in PDF /Subject metadata."
    },
    "author": {
      "type": "string",
      "maxLength": 160,
      "description": "Optional author or organization name rendered in the cover banner and PDF /Author metadata."
    },
    "theme": {
      "type": "string",
      "enum": [
        "executive",
        "invoice",
        "technical",
        "memo"
      ],
      "default": "executive",
      "description": "Corporate print styling theme ('executive', 'invoice', 'technical', or 'memo')."
    },
    "pageSize": {
      "type": "string",
      "enum": [
        "Letter",
        "A4",
        "Legal"
      ],
      "default": "Letter",
      "description": "Paper size ('Letter', 'A4', or 'Legal')."
    },
    "orientation": {
      "type": "string",
      "enum": [
        "portrait",
        "landscape"
      ],
      "default": "portrait",
      "description": "Page orientation ('portrait' or 'landscape')."
    },
    "headerText": {
      "type": "string",
      "maxLength": 180,
      "description": "Optional running header stamped at the top margin of every page."
    },
    "includePageNumbers": {
      "type": "boolean",
      "default": true,
      "description": "Include 'Page X of Y' running footers on every page."
    },
    "watermarkText": {
      "type": "string",
      "maxLength": 80,
      "description": "Optional diagonal watermark text rendered across every page (e.g. 'CONFIDENTIAL' or 'DRAFT')."
    }
  },
  "required": [
    "content"
  ],
  "additionalProperties": false
}
```

## Examples
### Render Q4 Executive Board Report with Financials Table
```bash
curl -X POST "https://pdf-forge.apikeg.com/v1/render-document-pdf" \
  -H "Content-Type: application/json" \
  -d '{"title":"Q4 Cloud FinOps Executive Summary","subtitle":"Quarterly Infrastructure Margin & Savings Audit","author":"Platform FinOps Team","theme":"executive","pageSize":"Letter","orientation":"portrait","contentFormat":"markdown","headerText":"ACME CORP — Q4 FINOPS AUDIT","includePageNumbers":true,"watermarkText":"CONFIDENTIAL","content":"## Highlights\n\nNet cloud margin improved **420 bps** quarter-over-quarter.\n\n| Service | Q3 Spend | Q4 Spend | Delta |\n| --- | ---: | ---: | ---: |\n| Compute | $142,000 | $118,500 | -16.5% |\n| Storage | $38,400 | $35,100 | -8.6% |\n\n> [!NOTE]\n> Reserved capacity commitments lock in an additional $95k annualized savings."}'
```
Expected output: Base64 PDF 1.7 binary, print-ready themed HTML, byteLength, and layoutDiagnostics (pageCount, lastPageFillRatio, wideTableWarnings, estimatedReadingMinutes).
