> 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/web/generate/template-based-generation/generate-via-template.md).

# Generate PDFs from a template in JavaScript

Here is your guide explaining how to generate document accurately and efficiently with JavaScript using Apryse SDK

## Overview

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

* You provide a [template](/web/generate/template-based-generation/data-model.md) in the form of an Office document (such as .docx)
* You provide [replacement data](/web/generate/template-based-generation/data-model.md#allowed-formats-for-values) 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

<a href="https://sdk.apryse.com/samples/web/samples/advanced/template-fill/" class="button primary">Launch Online Demo</a><a href="/web/generate/template-based-generation/generate-docx-template.md" class="button primary">Learn more</a>

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-83944acf8c30622179f3a098ac1deabcf42a616c%2Fd890bc566449ac649bfcc57c28f520f9f5049d3b-1440x480.png?alt=media)

## Samples

* [Template fill sample](/web/get-started/samples/template-fill.md)

## Next steps

* [Learn how to generate a PDF from a DOCX template](/web/generate/template-based-generation/generate-docx-template.md)
* [Learn about the template data model](/web/generate/template-based-generation/data-model.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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/generate/template-based-generation/generate-via-template.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
