Skip to main content
POST /format/v1/document Convert Markdown, JSON, or plain text into professionally formatted documents with full control over typography and layout.

Request

curl -X POST https://api.case.dev/format/v1/document \
  -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "# Legal Memorandum\n\nRe: Smith v. Jones...",
    "input_format": "md",
    "output_format": "pdf",
    "options": {
      "template": "standard",
      "header": "CONFIDENTIAL",
      "styles": {
        "h1": { "font": "Times New Roman", "size": 14, "bold": true, "alignment": "center" },
        "p": { "font": "Times New Roman", "size": 12, "spacingAfter": 12 }
      }
    }
  }'

Parameters

FieldTypeRequiredDescription
contentstringYesSource content to format
input_formatstringNoInput format: md, json, or text. Default: md
output_formatstringYesOutput format: pdf, docx, or html_preview
optionsobjectNoFormatting configuration (see below)

Options

Layout and branding

OptionTypeDescription
templatestringstandard (default) or pleading (legal paper with line numbers)
headerstringText for document header
footerstringText for document footer (supports {{page}} for page numbers)
marginsobject{ top, right, bottom, left } in points
imagesarrayImage objects: { url, width, height, align, x, y }

Element styles

The styles object lets you define the appearance of each element type:
Typescript
options: {
  styles: {
    h1: { font: 'Times New Roman', size: 16, bold: true, alignment: 'center' },
    h2: { font: 'Times New Roman', size: 14, bold: true },
    p: { font: 'Times New Roman', size: 12, spacingAfter: 12 },
    code: { font: 'Courier New', size: 10 },
    default: { font: 'Times New Roman', size: 12 }
  }
}
PropertyTypeDescription
fontstringFont family: Times New Roman, Arial, Georgia, Courier New
sizenumberFont size in points
boldbooleanBold text
alignmentstringleft, center, right, or justify
spacingBeforenumberSpace before element in points
spacingAfternumberSpace after element in points

Template components with variables

Use {{variable}} placeholders in your content, then provide values:
Typescript
options: {
  components: [{
    content: '# Agreement\n\nBetween {{party1}} and {{party2}}...',
    variables: {
      party1: 'Acme Corp',
      party2: 'Smith LLC'
    },
    styles: { /* optional overrides */ }
  }]
}
You can also reference saved templates by ID:
Typescript
options: {
  components: [{
    templateId: 'tmpl_abc123',
    variables: {
      party1: 'Acme Corp',
      party2: 'Smith LLC'
    }
  }]
}

Response

For pdf and docx

Returns binary file content with appropriate headers:
  • Content-Type: application/pdf or application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • Content-Disposition: attachment; filename="formatted.pdf" or formatted.docx

For html_preview

Returns HTML string:
<html>
  <head><title>Legal Memorandum</title></head>
  <body>
    <h1 style="font-family: Times New Roman; font-size: 14pt; text-align: center;">
      Legal Memorandum
    </h1>
    ...
  </body>
</html>

Examples

Court pleading with line numbers

# CLI (via cURL - no direct CLI command)
curl -X POST https://api.case.dev/format/v1/document \
  -H "Authorization: Bearer $CASEDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "# MOTION FOR SUMMARY JUDGMENT\n\n**CASE NO.:** 2024-CV-12345\n\nPlaintiff JOHN DOE hereby moves this Court for summary judgment...",
    "input_format": "md",
    "output_format": "pdf",
    "options": {
      "template": "pleading",
      "header": "SUPERIOR COURT OF CALIFORNIA, COUNTY OF LOS ANGELES",
      "footer": "MOTION FOR SUMMARY JUDGMENT - {{page}}",
      "margins": { "top": 72, "right": 72, "bottom": 72, "left": 108 }
    }
  }'

Contract with dynamic values

# CLI (via cURL - no direct CLI command)
curl -X POST https://api.case.dev/format/v1/document \
  -H "Authorization: Bearer $CASEDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "...",
    "input_format": "md",
    "output_format": "docx",
    "options": {
      "components": [{
        "variables": {
          "client_name": "Acme Corp",
          "effective_date": "01/15/2025",
          "term_length": "12 months",
          "monthly_fee": "$5,000"
        }
      }],
      "styles": {
        "h1": { "font": "Georgia", "size": 18, "alignment": "center" },
        "p": { "font": "Georgia", "size": 11, "spacingAfter": 8 }
      }
    }
  }'

Quick preview

# CLI (via cURL - no direct CLI command)
curl -X POST https://api.case.dev/format/v1/document \
  -H "Authorization: Bearer $CASEDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "# Your markdown here...",
    "output_format": "html_preview"
  }'

Error codes

StatusDescription
400Invalid input format, missing required fields, or template variable errors
401Invalid or missing API key
404Referenced template not found