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.
Endpoint
Section titled “Endpoint”POST https://api.docstron.com/v1/documents/quick/generateAuthentication
Section titled “Authentication”This endpoint requires authentication using a Bearer token. Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYParameters
Section titled “Parameters”Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
html | string | Yes | HTML content with optional placeholders (e.g., <h1>{{ customer_name }}</h1>) |
data | object | Yes | Key-value pairs to replace placeholders in the HTML (e.g., {"customer_name": "John Doe"}) |
response_type | string | Yes | Format of the response. Options: pdf, json_with_base64, or document_id |
extra_css | string | No | Additional CSS styling to apply to the document (e.g., @page { margin: 2cm; }) |
save_template | boolean | No | Whether to save the HTML as a reusable template. Default: false |
application_id | string | Conditional | Required when save_template is true. The application ID to associate the template with |
password | string | No | Optional password to protect the generated PDF document |
Response Type Options
Section titled “Response Type Options”| Value | Description |
|---|---|
pdf | Returns the PDF file directly in the HTTP response (binary) |
json_with_base64 | Returns JSON with base64-encoded PDF content and metadata |
document_id | Returns JSON with document ID and download URL |
Request Examples
Section titled “Request Examples”Generate with Direct PDF Response
Section titled “Generate with Direct PDF Response”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" }'Generate with Base64 Response
Section titled “Generate with Base64 Response”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" }'Generate with Document ID Response
Section titled “Generate with Document ID Response”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”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" }'Generate Password-Protected PDF
Section titled “Generate Password-Protected PDF”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!" }'Response
Section titled “Response”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 }}Response Fields
Section titled “Response Fields”| Field | Type | Description |
|---|---|---|
success | boolean | Indicates if the request was successful |
message | string | A message describing the response |
data.document_id | string | Unique identifier of the generated document |
data.template_id | string | Template ID if saved (null if save_template is false) |
data.download_url | string | URL to download the generated PDF |
data.size_bytes | integer | Size of the PDF file in bytes |
Error Responses
Section titled “Error Responses”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_typevalue (must bepdfordocument_id) - Missing required fields (
html,data, orresponse_type) application_idmissing whensave_templateistrue- 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.
Choosing Response Type
Section titled “Choosing Response Type”Use pdf when:
Section titled “Use pdf when:”- 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
Use document_id when:
Section titled “Use document_id when:”- 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
When to Use Quick Generate
Section titled “When to Use Quick Generate”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
HTML and CSS Guidelines
Section titled “HTML and CSS Guidelines”The Quick Generate endpoint supports standard HTML and CSS for document creation:
- Use semantic HTML5 elements
- Include inline styles or use the
extra_cssparameter - 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
Need Help?
Section titled “Need Help?”If you have questions or need assistance:
- 📧 Email: support@docstron.com
- 💬 Live Chat: Available in your dashboard
- 📚 Documentation: You’re reading it!