Main Content

Templates for DOM API Report Programs

The DOM API comes with default templates for each output type for formatting your report as it generates. Templates are useful for providing default design formats so that you do not need to specify them in your report. This approach is helpful if several reports have the same look, which is typical in most organizations. In your report program, you refer by name to the template and its styles and layouts. When your report generates, the template determines the appearance of the document objects.

Templates also enable form-based document generation. You can define fixed content and holes (blanks) in your template. Your report program can fill the holes with content, such as text or images. See Form-Based Reporting.

Another advantage of using templates is for maintenance. If your report design changes, you change only the template and not all the programs that use that design.

Using templates also keeps your report program smaller, because you do not need to specify properties for each object you create. For reports that are hundreds of pages, using templates might also improve performance.

You can create a copy of the default templates and customize them to specify the default formatting and layout of your reports. For the template to take effect, your report program must refer to your template and specify the style names and document parts to use.

You can create a copy of the default templates using the mlreportgen.dom.Document.createTemplate method. The default templates can serve as a starting point for your template.

Template Packages

All DOM templates, except for single-file HTML templates, consist of document, style sheet, and image files zipped into packages based on the Open Packaging Convention (OPC). A single-file HTML template embeds style sheets and images as HTML elements in the HTML document. You can use Microsoft® Word to edit Word templates (identified by a .dotx extension) directly. You can also edit single-file HTML templates directly using any text or HTML editor.

To edit multifile HTML templates (identified by an .htmtx extension) and PDF templates (identified by a .pdftx extension), you must first unzip them. You can optionally rezip an edited HTML or PDF template before using it to generate a report. The DOM API provides functions for zipping and unzipping multifile HTML and PDF templates: zipTemplate and unzipTemplate.


You can use styles defined in templates to format paragraphs, text, tables, lists, and so on. You can modify styles or create your own. See Use Style Sheet Styles.

Word templates include standard Word styles, such as Normal, Heading 1, and Title. You create and modify styles using standard Word techniques. See Modify Styles in Microsoft Word Templates.

HTML and PDF templates define styles using CSS properties in template files that end with .css. For details, see Modify Styles in HTML Templates and Modify Styles in PDF Templates

Page Layout

You can use templates to define the page layout of Word and PDF reports, including the size, orientation (portrait or landscape), margins, and page headers and footers. You can use a template to define different page layouts for different sections of a document. See Create Page Layout Sections.

You can also define page layouts programmatically or use a combination of layouts that are defined programmatically and in a template.

Document Part Templates

A document part template is a template for a repeatable structure in your report. You can insert an instance of a document part in your report from your report program using a DocumentPart object. You create document part templates in a document part template library.

For Word templates, you define document part templates and store them in the Word Quick Parts Gallery, which serves as the library. The default template does not include any document part templates. To create them, see Create Microsoft Word Document Part Template Library.

For HTML and PDF, the default template contains a document part template library file named docpart_templates.html. This file creates the library and contains some default document part templates. You can modify or delete the supplied document part templates and add your own. See Create HTML Document Part Template Library and Create PDF Document Part Template Library.

See Also

| |

Related Topics