---
title: "Export the current document as a styled .docx (default), .pdf, .html, .md, or .txt file with full fidelity."
method: POST
path: "/v1/documents/export"
tags: ["v1", "mcp"]
---

# Export the current document as a styled .docx (default), .pdf, .html, .md, or .txt file with full fidelity.

`POST /v1/documents/export`

## Request

- Base URL: `https://api.superdocs.app`
- URL: `https://api.superdocs.app/v1/documents/export`
- Auth: HTTP bearer

Round-trips the document through the original docx renderer, preserving tables, borders, shading, alternating row colors, headers, footers, fonts, inline styling, and embedded images. Two modes: pass html directly to export ad-hoc content, OR pass session_id to export the session's current state. Format options: 'docx' (default, native Open XML, best for programmatic processing or mail merge), 'pdf', 'html', 'markdown', or 'txt' ('doc' is a legacy Word-compatible HTML alias). Fidelity is the differentiator vs naive HTML to docx converters. When called as an MCP tool, binary formats (docx/pdf/doc) are returned as a short-lived signed download_url in a JSON envelope (fetch it to get the file); text formats (html/markdown/txt) are returned inline.

## Headers

- `authorization` string, nullable

## Request body

- ExportRequest: Unified request body for POST /v1/documents/export. Backward-compat notes: - Top-level ``filename`` is retained for legacy clients that sent only ``{ html }`` and relied on the filename being auto-extracted from the first <h1>. New clients should use ``options.filename`` — options.filename wins when both are set. - ``format`` defaults to "docx". Legacy callers passing format="doc" explicitly keep working during a short back-compat window.
  - `session_id` string, nullable: Session ID to export from (the document is taken from the session). Required if html is omitted.
  - `html` string, nullable: HTML content to export inline. Used instead of the session document if provided.
  - `format` 'docx' | 'pdf' | 'html' | 'markdown' | 'txt' | 'doc': Export format. One of docx (default), pdf, html, markdown, txt.
  - `options` ExportOptions: User-facing export customisation (page size, orientation, margins, filename, watermark). Sent on every export request.
    - `paper_size` 'A4' | 'Letter' | 'A3' | 'Legal': Page size for DOCX/PDF/legacy .doc. HTML/MD/TXT exports ignore.
    - `orientation` 'portrait' | 'landscape': Page orientation for DOCX/PDF/legacy .doc.
    - `margins` 'narrow' | 'normal' | 'wide' | 'custom': Page margins preset. 'narrow' = 0.5in, 'normal' = 1.0in, 'wide' = 1.5in. 'custom' uses custom_margins_inches.
    - `custom_margins_inches` object, nullable: Required when margins='custom'. Each value 0.25-3.0 inches.
    - `filename` string, nullable: Custom filename (no extension). Auto-detected from first <h1> if unset.
    - `embed_images` boolean: HTML export only. When True, images are base64-embedded for offline portability (raises size cap to 150 MB). When False, images are referenced by URL (smaller file, online-only).
    - `watermark_text` string, nullable: PDF only. Optional text watermark overlaid on every page.
    - `watermark_opacity` number: PDF watermark opacity, 0.05-1.0.
    - `fidelity` 'strict' | 'compat', nullable: Export fidelity. 'strict' (server default) renders only the formatting the document carries — no imposed table widths/borders (except visual defaults on fully unstyled tables), overflow-only clamping, highlight colors honored. 'compat' reproduces the legacy normalized output.
  - `filename` string, nullable: DEPRECATED. Use options.filename. Top-level kept for legacy callers.
  - `source_filename` string, nullable: The document's original/source filename (e.g. the name it was uploaded under). Used as the default export filename when no explicit options.filename is set, taking precedence over the first heading.
  - `upload_id` string, nullable: ID returned by /v1/uploads (large-document upload flow, for payloads above ~25 MB). When set, the route fetches the HTML body from the uploaded payload instead of using the html field.

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/superdocs/apis/universal-document-ai-api.md) · [All operations](https://skmtc.dev/superdocs/apis/universal-document-ai-api/llms.txt) · [OpenAPI document](https://skmtc.dev/superdocs/apis/universal-document-ai-api/revisions/37d03122940b?raw)
