Skip to content

Quick Generate Document

Generate a PDF document on-the-fly using HTML content and dynamic data. This endpoint allows you to create documents without setting up templates in advance, ideal for rapid prototyping or one-off document generation.

POST https://api.docstron.com/v1/documents/quick/generate

This endpoint requires authentication using a Bearer token. Include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Request Body

ParameterTypeRequiredDescription
htmlstringYesHTML content with optional placeholders (e.g., <h1>{{ customer_name }}</h1>)
dataobjectYesKey-value pairs to replace placeholders in the HTML (e.g., {"customer_name": "John Doe"})
response_typestringYesFormat of the response. Options: pdf, json_with_base64, or document_id
extra_cssstringNoAdditional CSS styling to apply to the document (e.g., @page { margin: 2cm; })
save_templatebooleanNoWhether to save the HTML as a reusable template. Default: false
application_idstringConditionalRequired when save_template is true. The application ID to associate the template with
passwordstringNoOptional password to protect the generated PDF document
ValueDescription
pdfReturns the PDF file directly in the HTTP response (binary)
json_with_base64Returns JSON with base64-encoded PDF content and metadata
document_idReturns JSON with document ID and download URL

Terminal window
curl --location 'https://api.docstron.com/v1/documents/quick/generate' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data-raw '{
"html": "<h1>Invoice {{ invoice_id }}</h1><p>Customer: {{ customer_name }}</p>",
"data": {
"invoice_id": "INV-438746",
"customer_name": "John Doe"
},
"response_type": "pdf"
}'
Terminal window
curl --location 'https://api.docstron.com/v1/documents/quick/generate' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data-raw '{
"html": "<h1>Invoice {{ invoice_id }}</h1><p>Customer: {{ customer_name }}</p>",
"data": {
"invoice_id": "INV-438746",
"customer_name": "John Doe"
},
"response_type": "json_with_base64"
}'
Terminal window
curl --location 'https://api.docstron.com/v1/documents/quick/generate' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data-raw '{
"html": "<h1>Invoice {{ invoice_id }}</h1><p>Customer: {{ customer_name }}</p>",
"data": {
"invoice_id": "INV-438746",
"customer_name": "John Doe"
},
"response_type": "document_id"
}'

Generate with Custom CSS and Save Template

Section titled “Generate with Custom CSS and Save Template”
Terminal window
curl --location 'https://api.docstron.com/v1/documents/quick/generate' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data-raw '{
"html": "<h1>Invoice {{ invoice_id }}</h1><p>Amount: {{ amount }}</p>",
"data": {
"invoice_id": "INV-438746",
"amount": "$299.00"
},
"extra_css": "@page { margin: 2cm; } h1 { color: #333; font-size: 24px; }",
"response_type": "document_id",
"save_template": true,
"application_id": "app-9f99d8c9-9b3a-4efd-9151-578acee61234"
}'
Terminal window
curl --location 'https://api.docstron.com/v1/documents/quick/generate' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data-raw '{
"html": "<h1>Confidential Report</h1><p>For: {{ recipient_name }}</p><p>Date: {{ date }}</p>",
"data": {
"recipient_name": "John Doe",
"date": "2025-10-30"
},
"response_type": "pdf",
"password": "SecureDoc2025!"
}'

200 - Success Response (pdf)

When response_type is pdf, the response is the PDF file directly as binary content.

Content-Type: application/pdf

The response will prompt a file download in browsers or can be saved directly in your application.


200 - Success Response (document_id)

When response_type is document_id, the response includes a document ID and download URL.

{
"success": true,
"message": "Request successful",
"data": {
"document_id": "document-c04ac0be-fbc1-4004-bc15-e38c7c221234",
"template_id": null,
"download_url": "https://api.docstron.com/v1/documents/download/document-c04ac0be-fbc1-4004-bc15-e38c7c221234",
"size_bytes": 4991
}
}
FieldTypeDescription
successbooleanIndicates if the request was successful
messagestringA message describing the response
data.document_idstringUnique identifier of the generated document
data.template_idstringTemplate ID if saved (null if save_template is false)
data.download_urlstringURL to download the generated PDF
data.size_bytesintegerSize of the PDF file in bytes

400 - Limit Reached

Returned when you’ve exceeded your subscription’s monthly document generation limit.

{
"success": false,
"message": "You've reached the maximum monthly limit of 20 documents for your subscription.",
"data": []
}

Solution: Upgrade your subscription plan at Docstron Pricing or wait until your monthly limit resets.


422 - Validation Error

Returned when the request data fails validation.

{
"success": false,
"message": "Validation failed",
"errors": [
{
"field": "",
"message": "Value error, application_id is required when save_template is True",
"type": "value_error"
}
]
}

Common causes:

  • Invalid response_type value (must be pdf or document_id)
  • Missing required fields (html, data, or response_type)
  • application_id missing when save_template is true
  • Invalid data types

Solution: Check the error details and ensure all fields are properly formatted. When save_template is true, you must provide a valid application_id.


500 - Template Engine Error

Returned when there’s an error processing the HTML with the provided data.

{
"success": false,
"message": "Template engine error!",
"data": []
}

Common causes:

  • Missing data for required placeholders in HTML
  • Invalid placeholder syntax (use {{ variable_name }})
  • Malformed HTML content
  • Template rendering issues

Solution: Verify that all placeholders in your HTML have corresponding data in the data object. Check your HTML content for syntax errors and ensure placeholders follow the correct format.


  • You want to download the PDF immediately
  • Building a direct download endpoint
  • You don’t need to store the document ID
  • Integrating with systems that expect binary PDF responses
  • You need to store the document reference for later
  • Building asynchronous workflows
  • You want to provide a download link to users
  • You need to track or manage generated documents
  • You’re saving the template for future reuse

Quick Generate is ideal for:

  • Rapid prototyping and testing
  • One-off document generation
  • Dynamic documents that change frequently
  • Situations where creating a template in advance is unnecessary

Use the standard Generate endpoint when:

  • You’re generating documents repeatedly with the same layout
  • You want to manage and version your templates
  • You need better organization and reusability
  • You prefer separating template management from document generation

The Quick Generate endpoint supports standard HTML and CSS for document creation:

  • Use semantic HTML5 elements
  • Include inline styles or use the extra_css parameter
  • Placeholders should use double curly braces: {{ variable_name }}
  • CSS page rules can control page margins and layout: @page { margin: 2cm; }
  • Supported CSS features depend on the PDF rendering engine

If you have questions or need assistance:

  • 📧 Email: support@docstron.com
  • 💬 Live Chat: Available in your dashboard
  • 📚 Documentation: You’re reading it!