Getting Started

Our REST API provides programmatic access to DocPayload's enterprise-grade document generation capabilities. Build, manage, and generate documents directly from your applications.

Authentication

All API requests require secure authentication using API keys or JWT tokens passed in the Authorization header.

Base URL

https://api.docpayload.com/v1

Document Definition Features

The Document Definition is a powerful JSON object that describes your PDF layout, styles, and content with enterprise-grade flexibility.

Rich Text Formatting

Use bracket notation for inline text styling:

{
  "p": "[b]Welcome to Acme Corp Onboarding[/b]",
  "style": "roundedTitleStyle"
}
{
  "p": "We are delighted to have you join our team. [i]Your skills and experience will be a valuable addition to our company.[/i] Please read the instructions below carefully.",
  "style": "solidBorderStyle"
}

Supports: [b]bold[/b], [i]italic[/i], [ib]bold+italic[/ib], [fontcolor, red]colored text[/fontcolor], [fontsize, 14]size[/fontsize], [sub, -5]subscript[/sub], [sup, 7]superscript[/sup]

Example with chemical formulas: Water (H[sub, -5]2[/sup]O) and Carbon Dioxide (CO[sup, 7]2[/sup])

Interactive Form Fields

Embed form elements directly in text content:

// Text Input Fields
"p": "First Name: [textfield, firstName, 
      'Enter your first name', 180|16]"
"p": "Email: [textfield, email, 
      'Enter your email address', 190|16]"

// Dropdown Selection
"p": "Department: [choicefield, department, 
      HR | Engineering | Marketing | Sales, 1, 160|16]"

// Checkbox Fields  
"p": "Policy: [checkbox, policyAck, 
      'I have read and understood the policies', 12|12]"

Advanced Border Styling

Each border side can have different properties with sophisticated customization:

"roundedTitleStyle": {
  "padding": 10,
  "fontSize": 18,
  "bold": true,
  "color": "#000000",
  "borderTop": {
    "width": 2,
    "color": "#FF5733",
    "opacity": 1.0,
    "type": "SOLID",
    "radiusTopLeft": 10
  },
  "borderRight": {
    "width": 1.5,
    "color": "#FFC300",
    "opacity": 0.8,
    "type": "DASHED",
    "radiusTopRight": 10
  },
  "borderBottom": {
    "width": 2,
    "color": "#DAF7A6",
    "opacity": 1.0,
    "type": "DOTTED",
    "radiusBottomRight": 10
  },
  "borderLeft": {
    "width": 1.5,
    "color": "#FF33A1",
    "opacity": 0.9,
    "type": "SOLID",
    "radiusBottomLeft": 10
  }
}

Border types: SOLID, DASHED, DOTTED with individual opacity, width, color, and corner radius per side

Table Structure

Create structured tables with form fields and different cell styles:

{
  "table": {
    "widths": [50, 50],
    "rows": [
      [
        { "p": "Personal Information", 
          "style": "headerStyle" },
        { "p": "Contact Details", 
          "style": "headerStyle" }
      ],
      [
        { "p": "First Name: [textfield, firstName, 
               'Enter name', 180|16]", 
          "style": "tableCellStyle" },
        { "p": "Email: [textfield, email, 
               'Enter email', 190|16]", 
          "style": "tableCellStyle" }
      ]
    ],
    "style": "tableStyle"
  }
}

Style System

Define reusable styles with comprehensive properties:

"styles": {
  "roundedTitleStyle": {
    "padding": 10,
    "fontSize": 18,
    "bold": true,
    "color": "#000000",
    "borderTop": { 
      "width": 2, "color": "#FF5733", 
      "type": "SOLID", "radiusTopLeft": 10 
    }
  },
  "headerStyle": {
    "backgroundColor": "#E2EAF4",
    "bold": true
  }
}
{
  "styles": {
    "headerStyle": { "fontSize": 22, "bold": true, "color": "#0a74da" },
    "bodyStyle": { "fontSize": 14, "color": "#333", "lineHeight": 1.5 },
    "tableStyle": { "border": "1pt solid #ccc", "textAlign": "center" },
    "tableHeaderStyle": { "bold": true, "backgroundColor": "#f0f0f0" }
  },
  "document": {
    "pageSize": "A4",
    "content": [
      { "h1": "You’re Invited!", "style": "headerStyle" },
      { "p": "Please confirm: [textfield, attendance, '', 150|20]", "style": "bodyStyle" },
      {
        "ul": {
          "symbol": "–",
          "style": "bodyStyle",
          "items": [
            { "p": "Select role: [choicefield, role, 'Admin | Editor | Viewer', 100|20]" },
            { "p": "Agree to terms: [checkbox, agreeTerms, '', 12|12]" }
          ]
        }
      },
      {
        "table": {
          "style": "tableStyle",
          "widths": ["25%", "25%", "25%", "25%"],
          "rows": [
            [
              { "h1": "Field", "style": "tableHeaderStyle" },
              { "h1": "Value", "style": "tableHeaderStyle" },
              { "h1": "Notes", "style": "tableHeaderStyle" },
              { "h1": "Extra", "style": "tableHeaderStyle" }
            ],
            [
              { "p": "[textfield, name, '', 140|20]" },
              { "p": "User avatar: [img, avatar.png, 24|24]" },
              { "p": "Upload before event" },
              { "p": "Additional info" }
            ]
          ]
        }
      }
    ]
  }
}

Key Features Summary

  • documentDefinition: Root container for the document structure with content array and styles object.
  • content: Array of content blocks including paragraphs, tables, and form fields with rich formatting.
  • styles: Named style objects with sophisticated border controls:
    • Individual Border Sides: Each side (top, right, bottom, left) can have different width, color, opacity, type, and corner radius
    • Border Types: SOLID, DASHED, DOTTED with full customization
    • Corner Radius: radiusTopLeft, radiusTopRight, radiusBottomLeft, radiusBottomRight
  • Form Fields: Interactive elements embedded within paragraph content:
    • [textfield, name, placeholder, width|height] — Text input fields
    • [choicefield, name, option1 | option2 | option3, selectedIndex, width|height] — Dropdown selections
    • [checkbox, name, label, width|height] — Checkbox inputs
  • Rich Text Formatting: Bracket notation for inline styling:
    • [b]bold[/b], [i]italic[/i], [ib]bold+italic[/ib]
    • [fontcolor, red]colored text[/fontcolor], [fontsize, 14]sized text[/fontsize]
    • [sub, -5]subscript[/sub], [sup, 7]superscript[/sup] with positioning
  • Table System: Complex tables with different cell styles, embedded form fields, and sophisticated border styling.
  • Professional Use Cases: Perfect for onboarding forms, contracts, surveys, reports, and any document requiring both presentation and data collection.

Real-world Example: The sample demonstrates a complete employee onboarding form with sophisticated styling, multiple form field types, rich text formatting with chemical formulas, and professional table layouts - all defined in a single JSON structure that generates a fully interactive PDF document.

Endpoints

Documents

  • GET /documents — List all documents
  • POST /documents — Create a new document
  • GET /documents/{id} — Get document details
  • PUT /documents/{id} — Update document
  • DELETE /documents/{id} — Delete document

Templates

  • GET /templates — List all templates
  • POST /templates — Create a new template
  • GET /templates/{id} — Get template details

Generation

  • POST /generate — Generate document from template
  • GET /generate/{id}/status — Check generation status

Interactive API Examples

Create Document

POST /documents

Generate PDF

POST /generate