Skip to main content
Populate fields inside a DOCX template using SuperDoc annotations. Create a template once with placeholder fields, then generate customized documents by providing field values.

Usage

import Casedev from 'casedev';

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

const document = await client.superdoc.v1.annotate({
  document: {
    url: 'https://your-bucket.s3.amazonaws.com/templates/contract.docx'
  },
  fields: [
    { id: 'client_name', type: 'text', value: 'Acme Corporation' },
    { id: 'contract_date', type: 'date', value: '2025-01-15' },
    { id: 'contract_amount', type: 'number', value: 50000 }
  ],
  output_format: 'pdf'
});

Parameters

ParameterTypeRequiredDescription
documentobjectYesDocument source (see below)
fieldsarrayYesFields to populate (see below)
output_formatstringNoOutput format: docx or pdf. Default: docx

Document object

Provide either a URL or base64-encoded content:
PropertyTypeDescription
urlstringURL to the DOCX template
base64stringBase64-encoded DOCX template

Field object

PropertyTypeRequiredDescription
idstringOne ofTarget field ID (for single field)
groupstringOne ofTarget field group (for multiple fields)
typestringYesField type: text, image, date, number
valuestring/numberYesValue to populate
optionsobjectNoAdditional options (e.g., image dimensions)

Field types

TypeValue FormatUse Case
textStringNames, descriptions, addresses
numberNumberAmounts, quantities, prices
dateISO date stringContract dates, deadlines
imageImage URLSignatures, logos, stamps

Response

Returns the annotated document as binary data with appropriate content type based on output_format.

Examples

Fill a contract template

const contract = await client.superdoc.v1.annotate({
  document: {
    url: 'https://templates.example.com/service-agreement.docx'
  },
  fields: [
    { id: 'client_name', type: 'text', value: 'Acme Corporation' },
    { id: 'client_address', type: 'text', value: '123 Main St, Suite 100' },
    { id: 'effective_date', type: 'date', value: '2025-01-15' },
    { id: 'monthly_fee', type: 'number', value: 5000 },
    { id: 'term_months', type: 'number', value: 12 }
  ],
  output_format: 'pdf'
});

// Send to client
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename="contract.pdf"');
res.send(contract);

Add signature to document

const signed = await client.superdoc.v1.annotate({
  document: {
    url: 'https://templates.example.com/agreement.docx'
  },
  fields: [
    { id: 'signatory_name', type: 'text', value: 'John Smith' },
    { id: 'signature_date', type: 'date', value: '2025-01-15' },
    {
      id: 'signature',
      type: 'image',
      value: 'https://signatures.example.com/john-smith.png',
      options: { width: 200, height: 50 }
    }
  ],
  output_format: 'pdf'
});

Use field groups for repeated content

When your template has multiple fields with the same tag (e.g., a header and footer both showing client name), use group instead of id:
const document = await client.superdoc.v1.annotate({
  document: { url: templateUrl },
  fields: [
    // Updates all fields tagged with "client_name" group
    { group: 'client_name', type: 'text', value: 'Acme Corporation' }
  ]
});

Creating templates

To create a template for use with the Annotate API:
  1. Create a DOCX document in Microsoft Word or Google Docs
  2. Add SuperDoc annotation fields where you want dynamic content
  3. Upload the template to a publicly accessible URL or your storage
  4. Call the Annotate API with field values
See SuperDoc’s documentation for details on adding annotation fields to your templates.