Document Templates

Description

An overview of the Document Template component, a fast alternative to Reports for generating PDF or Word documents using JSON data.

Discussion

A new component type (Document Templates) is available. A Document Template is a data and layout definition that is stored as a JSON definition. Document Templates can be used to generate .PDF or Microsoft Word .docx files by merging data into a template.

The advantage of Document Templates over using the Report feature to generate PDF files is speed. Generating a PDF file using a Document Template is extremely fast.

Creating a Document Template

To create a new Document Template, select the Document Template item in the Categories list in the Web Projects Control Panel, then click the New button in the toolbar.

images/doctemplate1.jpg

A builder for the Document Template is then shown.

images/doctemplate.jpg

Defining Data and Layout

The easiest way to get started is to import a report definition by clicking the Import report definition hyperlink at the bottom right of the dialog. This will populate both the Data tab and the Layout tab in the builder.

If you prefer to build the Document Template manually, click the Define datasource... hyperlink. This will open a dialog where you can define the data source for the Document Template.

images/doctemplatedatasource.jpg

If you want to define a SQL data source, click the Define SQL Datasource.. button. Once you have defined the connection string and query for the datasource, the screen will change.

images/doctemplate10.jpg

Click the Pick Fields and Groups... hyperlink to pick the fields that will appear in the report. If you want to group your data you can specify fields to group the data on. When you click on the Pick Fields and Groups... hyperlink the following dialog is shown:

images/doctemplate11.jpg

Once you have completed the definition of the Document Template datasource you can select the Layout tab to define the layout of the Document Template.

images/dictemplate40.jpg

If you did not import a report you will need to define the Layout yourself.

images/doctemplate50.jpg

Layout Helper Functions

There are a number of helper functions to generate a default Layout. These are:

Generate Layout From Data...

This option generates a Layout based on the shape of the JSON data defined in the Data tab.

Import Word File...

This option allows you to import a Microsoft Word Merge document template.

Create from HTML...

This option allows you to define an HTML template that contains placeholders for fields in the data.

When you click the Generate Layout From Data hyperlink, the following dialog is shown. You can generate a layout that displays data in a columnar or 'form' layout and you can turn on page headers and footers for the generated layout. When you turn on a header or footer, you specify what content should be shown in the header or footer.

images/doctemplate60.jpg

Previewing the Document

Once you have defined the layout for the Document Template, you can preview it by clicking the Preview Document... hyperlink.

See Also