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

const response = await client.format.v1.document({
  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:
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:
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:
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

const pleading = await client.format.v1.document({
  content: `
# MOTION FOR SUMMARY JUDGMENT

**CASE NO.:** 2024-CV-12345

Plaintiff 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

const contract = await client.format.v1.document({
  content: contractTemplate,
  input_format: 'md',
  output_format: 'docx',
  options: {
    components: [{
      variables: {
        client_name: formData.clientName,
        effective_date: new Date().toLocaleDateString(),
        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

// Fast HTML preview for UI rendering
const preview = await client.format.v1.document({
  content: userMarkdown,
  output_format: 'html_preview'
});

// Embed in your app
previewContainer.innerHTML = preview;

Error codes

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