Class: mlreportgen.dom.Document
Package: mlreportgen.dom

Create DOM template file


mlreportgen.dom.Document.createTemplate(path) creates a copy of the default DOM template file in the specified location. The file extension indicates the type of template file to create.


mlreportgen.dom.Document.createTemplate(path,type) creates a template file of the specified type in the specified location. If the path does not have an extension, the method appends the extension .htmtx for HTML, .dotx for Word, pdftx for PDF, or .htmt for single-file HTML.

To use a template you created programmatically with Report Explorer, set these OPC core properties on the new template using mlreportgen.dom.Document.getCoreProperties and mlreportgen.dom.Document.setCoreProperties:

  • Description

  • Identifier

  • Title


expand all

Create a Microsoft® Word template file in the current folder.

import mlreportgen.dom.*

Create a template. Apply the core OPC properties to it so that you can access the template in Report Explorer.

import mlreportgen.dom.*;

cp = Document.getCoreProperties('pdf_template.pdftx');
cp.Description = 'A pdf template for form-based reports';
cp.Identifier = 'mypdf-form-template';
cp.Title = 'My PDF Template';


Move the template to a folder on the MATLAB® path. To use the template in the current MATLAB session, update the template cache so that the template appears in Report Explorer.


If Report Explorer is already open, the new template appears as an option on the list of templates you can use. If the document conversion template editor was already open, close it and reopen it to see the new template.

Input Arguments

expand all

Path for the template file you want to create, specified as a character vector. If you use the path argument without the type argument, include the template extension: .htmtx for HTML, .docx for Word, .pdftx, or .htmt for single-file HTML.

If you use both the path and type arguments, and you do not specify an extension for path, the createTemplate method adds the appropriate extension to the new template.

Type of template, specified as:

  • 'html' for HTML.

  • 'docx' for Word.

  • 'pdf' for PDF.

  • 'html-file' for single-file HTML. HTML output consists of a single file that contains the text, style sheets, JavaScript®, and images for the report.

The template type must match the type you specified using the path argument. If the path argument did not include an extension, the type argument determines the extension for this method to use.


Invoke createTemplate on the mlreportgen.dom.Document class, not on an instance of that class. In other words, use Document.createTemplate, not myDocument.createTemplate.

Introduced in R2014b