> ## Documentation Index
> Fetch the complete documentation index at: https://docs.case.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Convert Documents

> Convert documents between DOCX, PDF, Markdown, and HTML formats

Convert documents between formats using [SuperDoc's](https://docs.superdoc.dev/getting-started/introduction) high-fidelity conversion engine.

## Usage

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/superdoc/v1/convert \
    -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
    -F "file=@document.docx" \
    -F "from=docx" \
    -F "to=pdf" \
    -o output.pdf

  # JSON body with base64
  curl -X POST https://api.case.dev/superdoc/v1/convert \
    -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "document_base64": "IyBIZWxsbyBXb3JsZA==",
      "from": "md",
      "to": "docx"
    }' \
    -o output.docx

  # JSON body with URL
  curl -X POST https://api.case.dev/superdoc/v1/convert \
    -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "document_url": "https://example.com/document.docx",
      "from": "docx",
      "to": "pdf"
    }' \
    -o output.pdf
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
    --file-url "https://example.com/document.docx" \
    --output-format pdf
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}

  const client = new Casedev({ apiKey: 'sk_case_YOUR_API_KEY' });

  // Using file upload
  const pdf = await client.superdoc.v1.convert({
    file: documentFile,
    from: 'docx',
    to: 'pdf'
  });

  // Using base64
  const docx = await client.superdoc.v1.convert({
    document_base64: Buffer.from(markdownContent).toString('base64'),
    from: 'md',
    to: 'docx'
  });

  // Using URL
  const result = await client.superdoc.v1.convert({
    document_url: 'https://example.com/document.docx',
    from: 'docx',
    to: 'pdf'
  });
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import base64

  client = casedev.Casedev(api_key='sk_case_YOUR_API_KEY')

  # Using file upload
  with open('document.docx', 'rb') as f:
      pdf = client.superdoc.v1.convert(
          file=f,
          from_='docx',
          to='pdf'
      )

  # Using base64
  content_b64 = base64.b64encode(markdown_content.encode()).decode()
  docx = client.superdoc.v1.convert(
      document_base64=content_b64,
      from_='md',
      to='docx'
  )
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  	FileURL:      casedev.F("https://example.com/document.docx"),
  	OutputFormat: casedev.F("pdf"),
  })
  ```
</CodeGroup>

## Parameters

| Parameter         | Type   | Required | Description                                  |
| ----------------- | ------ | -------- | -------------------------------------------- |
| `file`            | File   | One of   | Document file (multipart upload)             |
| `document_url`    | string | One of   | URL to fetch document from                   |
| `document_base64` | string | One of   | Base64-encoded document content              |
| `from`            | string | Yes      | Source format: `docx`, `md`, `html`          |
| `to`              | string | No       | Target format: `pdf`, `docx`. Default: `pdf` |

## Supported conversions

| From   | To     | Notes                      |
| ------ | ------ | -------------------------- |
| `docx` | `pdf`  | Full fidelity conversion   |
| `md`   | `docx` | Converts Markdown to Word  |
| `md`   | `pdf`  | Markdown to PDF (via DOCX) |
| `html` | `docx` | HTML content to Word       |

## Response

Returns the converted document as binary data with appropriate content type:

* `application/pdf` for PDF output
* `application/vnd.openxmlformats-officedocument.wordprocessingml.document` for DOCX output

## Examples

### Convert uploaded file

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/superdoc/v1/convert \
    -H "Authorization: Bearer $CASEDEV_API_KEY" \
    -F "file=@document.docx" \
    -F "from=docx" \
    -F "to=pdf" \
    -o converted.pdf
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev superdoc convert
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  export async function POST(request: Request) {
    const formData = await request.formData();
    const file = formData.get('file') as File;

    const pdf = await client.superdoc.v1.convert({
      file: file,
      from: 'docx',
      to: 'pdf'
    });

    return new Response(pdf, {
      headers: {
        'Content-Type': 'application/pdf',
        'Content-Disposition': 'attachment; filename="converted.pdf"'
      }
    });
  }
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  with open('document.docx', 'rb') as f:
      pdf = client.superdoc.v1.convert(
          file=f,
          from_='docx',
          to='pdf'
      )

  # Save the converted PDF
  with open('converted.pdf', 'wb') as out:
      out.write(pdf)
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  	From:        casedev.F(casedev.SuperdocV1ConvertParamsFromDocx),
  	To:          casedev.F(casedev.SuperdocV1ConvertParamsToPdf),
  	DocumentURL: casedev.F("https://example.com/document.docx"),
  })
  // resp is *http.Response with PDF body
  ```
</CodeGroup>

### Generate Word doc from Markdown

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/superdoc/v1/convert \
    -H "Authorization: Bearer $CASEDEV_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "document_base64": "IyBRdWFydGVybHkgUmVwb3J0Li4u",
      "from": "md",
      "to": "docx"
    }' \
    -o report.docx
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev superdoc convert
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const markdown = `
  # Quarterly Report

  ## Executive Summary
  Revenue increased by 15% compared to Q3...

  ## Key Metrics
  | Metric | Value |
  |--------|-------|
  | Revenue | $1.2M |
  | Growth | 15% |
  `;

  const docx = await client.superdoc.v1.convert({
    document_base64: Buffer.from(markdown).toString('base64'),
    from: 'md',
    to: 'docx'
  });

  fs.writeFileSync('report.docx', docx);
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}

  markdown = """
  # Quarterly Report

  ## Executive Summary
  Revenue increased by 15% compared to Q3...

  ## Key Metrics
  | Metric | Value |
  |--------|-------|
  | Revenue | $1.2M |
  | Growth | 15% |
  """

  content_b64 = base64.b64encode(markdown.encode()).decode()
  docx = client.superdoc.v1.convert(
      document_base64=content_b64,
      from_='md',
      to='docx'
  )

  with open('report.docx', 'wb') as f:
      f.write(docx)
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}

  markdown := "# Quarterly Report\n\n## Executive Summary\nRevenue increased by 15% compared to Q3...\n\n## Key Metrics\n| Metric | Value |\n|--------|-------|\n| Revenue | $1.2M |\n| Growth | 15% |"

  resp, _ := client.Superdoc.V1.Convert(ctx, casedev.SuperdocV1ConvertParams{
  	DocumentBase64: casedev.F(base64.StdEncoding.EncodeToString([]byte(markdown))),
  	From:           casedev.F(casedev.SuperdocV1ConvertParamsFromMd),
  	To:             casedev.F(casedev.SuperdocV1ConvertParamsToDocx),
  })
  // resp is *http.Response with DOCX body
  ```
</CodeGroup>

## Limits

| Limit               | Value          |
| ------------------- | -------------- |
| Max file size       | 25 MB          |
| Concurrent requests | 10 per API key |
