← Back to Adapters

Generate document

Generate a document from a template and case data using the appropriate rendering engine

Overview

The Document Generation activity generates a PDF document by rendering a template with case-specific input data. It returns the raw PDF content — the handler is responsible for storing it in file storage and constructing the attachment metadata for state.

Usage

Called once per document to generate. The handler iterates over documentsToGenerate in each document package and calls this activity for each.

Handler responsibilities:

  1. Select the generator for this document (e.g., STACC_DOCUMENT_GENERATION, SPAMA)
  2. Narrow the relevant standard-model entities from case state into inputData
  3. Call this activity with generator, templateName, and inputData
  4. Receive the PDF buffer
  5. Store it via fileStorage.storeFile()
  6. Construct attachment metadata and update state

Request

  • Endpoint: /document-generation/generate
  • Method: POST

Request body:

  • generator (required): Which document generation engine to use (STACC_DOCUMENT_GENERATION, SPAMA, or others)
  • templateName (required): Template identifier, e.g., ACCEPTANCE_LETTER, CUSTOMER_LETTER, FIXED_RATE_AGREEMENT
  • inputData (required): Template-specific data payload built from narrowed standard-model types

Input Data

The inputData is built from narrowed subsets of standard-model types. The handler selects which entities are relevant for each template and strips fields the template does not need.

For example, an acceptance letter might include:

  • parties — narrowed to names and NIN (from Party.personalInformation)
  • financing.loanAgreements — narrowed to loan amount, interest rate, and repayment period
  • collateralObjects — narrowed to address

A mortgage deed would instead focus on collateral objects, agreements, and cadastre data.

The full standard-model structures are not sent — only the subset each template requires.

Template names are identifiers configured in the template management system (e.g., control panel). The list is not finite — new templates can be added without changes to this adapter. Examples of existing templates:

  • CUSTOMER_LETTER — Parties, financing terms, addresses
  • ACCEPTANCE_LETTER — Agreement details, acceptance terms
  • FIXED_RATE_AGREEMENT — Interest rates, repayment terms
  • MORTGAGE_DEED — Collateral details, ownership, cadastre data
  • PLEDGE_DECLARATION — Collateral agreement, guarantor info

Response

  • Content-Type: application/pdf
  • Body: Raw PDF document as binary stream

Data Flow

  1. Handler narrows standard-model entities from case state into inputData
  2. POST /document-generation/generate with generator, templateName, and inputData
  3. Adapter renders template and returns PDF buffer
  4. Handler stores in fileStorage, constructs metadata, and updates state