> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/appian/template-generation/template-generation.md).

# Template generation in Appian

Generate dynamic PDFs with Apryse's office template generation framework. Design templates in Office documents and merge data with ease using Apryse SDK. Explore loops, conditionals, images, and more.

## Overview

Apryse's office template generation framework enables the dynamic generation of PDFs:

* You provide a template in the form of an Office document (such as .docx)
* You provide replacement data in JSON form
* Apryse SDK will efficiently generate a PDF by merging the data with the template
* Fully featured, with support for loops, conditionals, images, table generation, etc.
* Use your preferred office editor to design attractive templates, and Apryse will take care of the rest
* All logic is entirely contained within the SDK, with no external dependencies

## Template Structure

If you have an Office document with template values that look like this:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
{{sender.name}} // object structure
```

{% endcode %}
{% endtab %}
{% endtabs %}

or

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
{{first_name}} // normal tag
```

{% endcode %}
{% endtab %}
{% endtabs %}

You can insert values to replace those template placeholders. This can be done in various ways.

## Filling a Template

The first is to set the `templateDataValues` parameter with a object that has keys that match the ones in the template and their associated value. They can be objects as seen in the placeholder key example above. Here is a sample of how this could look like in expression mode in Appian Designer:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
a!localVariables(
  local!data: a!queryEntity(
    entity: cons!WT_DS_User,
    query: a!query(
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: -1
      )
    )
  ).data[1],
  a!headerContentLayout(
    header: {
      a!billboardLayout(
        backgroundMedia: a!documentImage(document: a!EXAMPLE_BILLBOARD_IMAGE()),
        backgroundColor: "#f0f0f0",
        marginBelow: "NONE",
        overlay: a!barOverlay(contents: {})
      )
    },
    contents: {
      webviewer(
        label: "WebViewer",
        labelPosition: "ABOVE",
        validations: {},
        height: "AUTO",
        key: null,
        url: null,
        appianDocId: 1249,
        documentFolder: null,
        userDisplayName: null,
        enabledElements: null,
        disabledElements: null,
        docAccessConnectedSystem: cons!WT_CS,
        loadAsPDF: null,
        enableAnnotations: null,
        notesInLeftPanel: null,
        darkMode: null,
        defaultLanguageCode: null,
        customCSSPath: null,
        fullAPI: null,
        enableRedaction: null,
        enableMeasurement: null,
        enableExtractPagesToAppian: null,
        newSavedDocumentIdValue: null,
        newSavedDocumentIdSaveInto: null,
        xfdfAnnotationDataValue: null,
        xfdfAnnotationDataSaveInto: null,
        enableDocumentGeneration: true,
        templateDataValue: {
          logo: local!data.firstName,
          date: local!data.firstName,
          sender: {
            name: local!data.firstName
          },
          dest: {
            title: "Mr.", /* hardcoded text value */
            given_name: local!data.firstName, /* value from variable */
            surname: local!data.lastName,
            address: "Earth"
          },
          client: {
            full_name: local!data.firstName,
            gender_posessive: "Male",
          },
          lease_problem: "none",
          land_location: "Earth",
        }
      )
    }
  )
)
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Manually set values with modal

You can also enable the `enableDocumentGeneration` parameter to gain access to a modal that allows users to manually set those values. This is, however, limited to just text/numerical values.

## Additional documentation

For more details, such as complex use cases like conditionals, loops, images and more visit our [WebViewer guide on generating via template](/web/generate/template-based-generation/generate-via-template.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/appian/template-generation/template-generation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
