# Render a document (/docs/api-reference/documents/create)

> Validates data against the template's schema and renders a PDF, or one page as a PNG with format: "png".

`POST https://druckling-nine.vercel.app/v1/documents`

Validates `data` against the template's schema and renders a PDF, or one page as a PNG with `format: "png"`. Answers 200 with the rendered document and its signed URL, or with `async: true` 202 with the queued document to poll or wait for by webhook. For e-invoice templates `data.invoice` is an EN 16931 invoice: Druckling computes the totals and VAT breakdown and produces the template's e-invoice format: Factur-X / ZUGFeRD (the CII XML embedded as `factur-x.xml` in a PDF/A-3), XRechnung 3.0 (UBL or CII XML) or Peppol BIS Billing 3.0 (UBL XML). XRechnung and Peppol templates produce `format: "xml"` documents (`application/xml`). A broken business rule answers 422 `validation_failed` with the offending `field`: EN 16931 (BR-xx), XRechnung (BR-DE-xx) or Peppol (PEPPOL-EN16931-xxx, PEPPOL-COMMON-xxx, DE-R-xxx between German parties).

## Request body (JSON Schema)

```json
{
  "type": "object",
  "properties": {
    "template": {
      "type": "string",
      "description": "Template slug, e.g. invoice-standard"
    },
    "version": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991,
          "exclusiveMinimum": 0
        },
        {
          "const": "latest"
        }
      ],
      "description": "Pinned version or `latest` (default)."
    },
    "filename": {
      "type": "string",
      "maxLength": 200
    },
    "data": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {},
      "description": "Payload matching the template schema."
    },
    "async": {
      "type": "boolean",
      "description": "Queue the render and return 202 immediately."
    },
    "format": {
      "enum": [
        "pdf",
        "png",
        "xml"
      ],
      "type": "string",
      "description": "Output format; the template decides the default (`xml` for XRechnung and Peppol BIS e-invoice templates, `pdf` otherwise). `png` renders one page as an image; a template's PDF/A or PDF/UA setting applies to PDFs only. Factur-X templates render to `pdf` only, XRechnung and Peppol templates to `xml` only, and `xml` needs one of those (422 on `format`)."
    },
    "image": {
      "type": "object",
      "properties": {
        "page": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991,
          "description": "Page to render (default 1); 422 on `image.page` if the document is shorter."
        },
        "scale": {
          "type": "number",
          "minimum": 0.5,
          "maximum": 4,
          "description": "Pixels per point (default 2 = 144 dpi; 1 = 72 dpi, 4 = 288 dpi)."
        }
      },
      "description": "PNG options; only allowed with `format: \"png\"`."
    },
    "language": {
      "type": "string",
      "maxLength": 35,
      "description": "Language to render: one of the template's `languages` (default: its default language). Texts without a translation fall back to the default language; numbers, dates, hyphenation and the PDF's language follow this one. A regional tag such as `de-AT` uses `de`. 422 `validation_failed` on this field for a language the template doesn't have."
    },
    "storage": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "bucket": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "description": "A bucket id from the Storage page, or `default` for the workspace's default bucket."
            }
          },
          "required": [
            "bucket"
          ]
        },
        {
          "const": false
        }
      ],
      "description": "Also copy the file to one of your own S3-compatible buckets (AWS S3, Cloudflare R2, Google Cloud Storage, Scaleway, Hetzner, OVHcloud, IONOS, MinIO…). The upload runs after the render (and signing, so the bucket gets the signed PDF), so it never slows the response; follow it in the document's `storage` or with the `document.delivered` / `document.delivery_failed` webhooks. Without this field the template's bucket rule applies, if there is one; `false` skips it. 422 `validation_failed` on `storage.bucket` for an unknown or disabled bucket."
    },
    "sign": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "object",
          "properties": {
            "certificate": {
              "type": "string",
              "maxLength": 64,
              "description": "Id of a certificate from Settings › Signing (default: the workspace's default certificate)."
            }
          }
        }
      ],
      "description": "Digitally sign the PDF (PAdES, invisible signature) with a certificate uploaded in Settings › Signing: `true` uses the default certificate, `{ \"certificate\": \"crt_…\" }` picks one. Unset: as the template says (its \"Sign rendered PDFs\" setting); `false` skips signing even then. PDF only (422 on `sign` for other formats). Signing is an incremental update, so PDF/A-3 (Factur-X) and PDF/UA documents keep their conformance. 404 on `sign.certificate` for an unknown certificate; 422 `signing_failed` when the workspace has no certificate, it has expired, or it can't sign."
    }
  },
  "required": [
    "template",
    "data"
  ]
}
```

## Response 200: Rendered

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "const": "document"
    },
    "status": {
      "enum": [
        "queued",
        "rendering",
        "rendered",
        "failed",
        "expired"
      ],
      "type": "string"
    },
    "template": {
      "type": "string"
    },
    "version": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ]
    },
    "filename": {
      "type": "string"
    },
    "format": {
      "enum": [
        "pdf",
        "png",
        "xml"
      ],
      "type": "string",
      "description": "`xml` for XRechnung and Peppol BIS e-invoices."
    },
    "content_type": {
      "type": "string",
      "description": "`application/pdf`, `image/png` or `application/xml`."
    },
    "image": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "page": {
              "type": "number",
              "description": "The page that was rendered (1-based)."
            },
            "scale": {
              "type": "number",
              "description": "Pixels per point: 2 = 144 dpi."
            },
            "width": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Pixel width, once rendered."
            },
            "height": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Pixel height, once rendered."
            }
          },
          "required": [
            "page",
            "scale",
            "width",
            "height"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set for `png` documents."
    },
    "pages": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "description": "Pages in the file (a PNG is one page; null for XML)."
    },
    "size_bytes": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ]
    },
    "url": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Signed download URL while the document is retained."
    },
    "expires_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "error": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "code",
            "message",
            "field"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "einvoice": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "format": {
              "enum": [
                "factur-x",
                "xrechnung",
                "peppol"
              ],
              "type": "string",
              "description": "`factur-x`: Factur-X 1.0 / ZUGFeRD 2.x hybrid invoice, a PDF/A-3 with the CII XML embedded. `xrechnung`: XRechnung 3.0 (German CIUS) as XML. `peppol`: Peppol BIS Billing 3.0 as UBL XML."
            },
            "syntax": {
              "enum": [
                "cii",
                "ubl"
              ],
              "type": "string",
              "description": "XML syntax: UN/CEFACT CII (Factur-X, XRechnung on request) or OASIS UBL 2.1 (XRechnung default, Peppol)."
            },
            "profile": {
              "type": "string",
              "description": "`EN 16931`, `XRechnung 3.0` or `Peppol BIS Billing 3.0`."
            },
            "customization_id": {
              "type": "string",
              "description": "Specification identifier (BT-24) written into the XML."
            },
            "attachment": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "File name of the XML embedded in the PDF; null when the document is the XML itself."
            }
          },
          "required": [
            "format",
            "syntax",
            "profile",
            "customization_id",
            "attachment"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set when the document is or carries an e-invoice (templates with e-invoicing on)."
    },
    "batch": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "index": {
              "type": "number",
              "description": "Position of the item in the batch's `items`."
            }
          },
          "required": [
            "id",
            "index"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set for documents rendered as part of a batch."
    },
    "language": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Language the document was rendered in (one of the template's `languages`); null for documents rendered before templates had languages."
    },
    "signature": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "certificate": {
              "type": "string",
              "description": "Id of the workspace certificate that signed the PDF."
            },
            "certificate_name": {
              "type": "string"
            },
            "subject": {
              "type": "string",
              "description": "The signer, from the certificate."
            },
            "level": {
              "enum": [
                "B-B",
                "B-T"
              ],
              "type": "string",
              "description": "PAdES baseline level (ETSI EN 319 142-1): `B-T` carries a trusted timestamp from a timestamp authority, `B-B` does not."
            },
            "signed_at": {
              "type": "string",
              "format": "date-time"
            },
            "test_certificate": {
              "type": "boolean",
              "description": "Signed with a Druckling test certificate, which proves nothing about the signer."
            }
          },
          "required": [
            "certificate",
            "certificate_name",
            "subject",
            "level",
            "signed_at",
            "test_certificate"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set when the PDF carries a digital signature (PAdES) applied by Druckling."
    },
    "storage": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "bucket": {
              "type": "string",
              "description": "Id of the bucket connection (Storage page)."
            },
            "status": {
              "enum": [
                "pending",
                "delivered",
                "failed"
              ],
              "type": "string",
              "description": "`pending` until the file is uploaded (retried with backoff for about 2.5 hours), then `delivered` or `failed`."
            },
            "key": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Object key in your bucket, from the bucket's path template."
            },
            "error": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "What the bucket answered on the last failed attempt, e.g. `403 AccessDenied: Access Denied`."
            },
            "attempts": {
              "type": "number"
            },
            "delivered_at": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "bucket",
            "status",
            "key",
            "error",
            "attempts",
            "delivered_at"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set when the document is also copied to your own S3-compatible bucket (request `storage`, or the template's bucket rule)."
    },
    "test_mode": {
      "type": "boolean"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "object",
    "status",
    "template",
    "version",
    "filename",
    "format",
    "content_type",
    "image",
    "pages",
    "size_bytes",
    "url",
    "expires_at",
    "error",
    "einvoice",
    "batch",
    "language",
    "signature",
    "storage",
    "test_mode",
    "created_at"
  ]
}
```

## Response 202: Queued (`async: true`)

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "const": "document"
    },
    "status": {
      "enum": [
        "queued",
        "rendering",
        "rendered",
        "failed",
        "expired"
      ],
      "type": "string"
    },
    "template": {
      "type": "string"
    },
    "version": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ]
    },
    "filename": {
      "type": "string"
    },
    "format": {
      "enum": [
        "pdf",
        "png",
        "xml"
      ],
      "type": "string",
      "description": "`xml` for XRechnung and Peppol BIS e-invoices."
    },
    "content_type": {
      "type": "string",
      "description": "`application/pdf`, `image/png` or `application/xml`."
    },
    "image": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "page": {
              "type": "number",
              "description": "The page that was rendered (1-based)."
            },
            "scale": {
              "type": "number",
              "description": "Pixels per point: 2 = 144 dpi."
            },
            "width": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Pixel width, once rendered."
            },
            "height": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Pixel height, once rendered."
            }
          },
          "required": [
            "page",
            "scale",
            "width",
            "height"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set for `png` documents."
    },
    "pages": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "description": "Pages in the file (a PNG is one page; null for XML)."
    },
    "size_bytes": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ]
    },
    "url": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Signed download URL while the document is retained."
    },
    "expires_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    },
    "error": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "code",
            "message",
            "field"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "einvoice": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "format": {
              "enum": [
                "factur-x",
                "xrechnung",
                "peppol"
              ],
              "type": "string",
              "description": "`factur-x`: Factur-X 1.0 / ZUGFeRD 2.x hybrid invoice, a PDF/A-3 with the CII XML embedded. `xrechnung`: XRechnung 3.0 (German CIUS) as XML. `peppol`: Peppol BIS Billing 3.0 as UBL XML."
            },
            "syntax": {
              "enum": [
                "cii",
                "ubl"
              ],
              "type": "string",
              "description": "XML syntax: UN/CEFACT CII (Factur-X, XRechnung on request) or OASIS UBL 2.1 (XRechnung default, Peppol)."
            },
            "profile": {
              "type": "string",
              "description": "`EN 16931`, `XRechnung 3.0` or `Peppol BIS Billing 3.0`."
            },
            "customization_id": {
              "type": "string",
              "description": "Specification identifier (BT-24) written into the XML."
            },
            "attachment": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "File name of the XML embedded in the PDF; null when the document is the XML itself."
            }
          },
          "required": [
            "format",
            "syntax",
            "profile",
            "customization_id",
            "attachment"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set when the document is or carries an e-invoice (templates with e-invoicing on)."
    },
    "batch": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "index": {
              "type": "number",
              "description": "Position of the item in the batch's `items`."
            }
          },
          "required": [
            "id",
            "index"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set for documents rendered as part of a batch."
    },
    "language": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Language the document was rendered in (one of the template's `languages`); null for documents rendered before templates had languages."
    },
    "signature": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "certificate": {
              "type": "string",
              "description": "Id of the workspace certificate that signed the PDF."
            },
            "certificate_name": {
              "type": "string"
            },
            "subject": {
              "type": "string",
              "description": "The signer, from the certificate."
            },
            "level": {
              "enum": [
                "B-B",
                "B-T"
              ],
              "type": "string",
              "description": "PAdES baseline level (ETSI EN 319 142-1): `B-T` carries a trusted timestamp from a timestamp authority, `B-B` does not."
            },
            "signed_at": {
              "type": "string",
              "format": "date-time"
            },
            "test_certificate": {
              "type": "boolean",
              "description": "Signed with a Druckling test certificate, which proves nothing about the signer."
            }
          },
          "required": [
            "certificate",
            "certificate_name",
            "subject",
            "level",
            "signed_at",
            "test_certificate"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set when the PDF carries a digital signature (PAdES) applied by Druckling."
    },
    "storage": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "bucket": {
              "type": "string",
              "description": "Id of the bucket connection (Storage page)."
            },
            "status": {
              "enum": [
                "pending",
                "delivered",
                "failed"
              ],
              "type": "string",
              "description": "`pending` until the file is uploaded (retried with backoff for about 2.5 hours), then `delivered` or `failed`."
            },
            "key": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Object key in your bucket, from the bucket's path template."
            },
            "error": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "What the bucket answered on the last failed attempt, e.g. `403 AccessDenied: Access Denied`."
            },
            "attempts": {
              "type": "number"
            },
            "delivered_at": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "bucket",
            "status",
            "key",
            "error",
            "attempts",
            "delivered_at"
          ]
        },
        {
          "type": "null"
        }
      ],
      "description": "Set when the document is also copied to your own S3-compatible bucket (request `storage`, or the template's bucket rule)."
    },
    "test_mode": {
      "type": "boolean"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "object",
    "status",
    "template",
    "version",
    "filename",
    "format",
    "content_type",
    "image",
    "pages",
    "size_bytes",
    "url",
    "expires_at",
    "error",
    "einvoice",
    "batch",
    "language",
    "signature",
    "storage",
    "test_mode",
    "created_at"
  ]
}
```