Main Content

Create a Custom HTML or PDF Template

You can copy a default template as the basis for your custom template. Alternatively, you can usemlreportgen.dom.Document.createTemplateto create a template programmatically.

Copy the Template

To customize the format styles used in the default HTML, single-file HTML, or PDF template, copy the template and modify or add style definitions in the copy.

  1. In Report Explorer, selectTools>Edit Document Conversion Template.

  2. In the Library pane, select the template you want to copy. For example, select theDefault HTML Template.

  3. In the Properties pane, clickCopy template.

  4. In the file browser, navigate to where you want to save the template file.

    选择一个路径,在MATLAB®path (for example, in theMATLABfolder in your home folder).

    Specify the file name, using the default file extension for an HTML template (.htmtx), single-file HTML template (.htmt), or PDF template (.pdftx). ClickSave.

  5. From the list of templates, select the template copy.

  6. In the dialog box, in theTemplate idandDisplay nameboxes, specify a unique ID and display name for the template.

    The display name is the name that appears in the Report Explorer list of templates. Use the template ID to identify a template in your code.

  7. To save the template properties you entered, click outside of the Properties pane.

分配一份报告模板

You can assign your template to a Report Explorer report.

  1. In the Report Explorer, selectReport Generatornode.

  2. From the list of reports, select the report you want to assign the template to.

  3. In the Report Options dialog box, setFile formatto one of the(from template)options. Select your template from the list.

Select an HTML Editor

By default, when you edit an HTML or PDF style sheet, the style sheet appears in the MATLAB Editor.

To use a different editor:

  1. In the Report Explorer, selectFile>Preferences.

  2. InEdit HTML Command, enter a MATLAB expression that opens the HTML editor you want to use. For example:

    system('Dreamweaver % &')

    When you open an HTML style sheet, the Report Explorer replacesFileNamewith the template that you selected. The ampersand (&) opens the editor in the background.

Edit HTML or PDF Templates

The templates consist of the main part (root.html), which defines the default page, and the document part templates (docpart_templates.html). For a single-file HTML template, all parts of the template are in a single file with an.htmtextension. You can make similar types of changes in these templates as you can in Word templates. SeeCustomize Microsoft Word Component Templates.

The HTML and PDF templates in Report Explorer are similar, with these exceptions:

  • PDF templates define a page layout, including page headers and footers. You can modify the document part templates for these layout elements. PDF templates can use a set of DOM API HTML tags supplied for this purpose. SeeDOM API HTML Elements.

  • PDF templates can use only a subset of standard HTML elements. SeeStandard HTML Elements.

HTML and PDF templates use DOM API HTML tags to define a document part library and the document part templates within them. Theelement defines the library. Your template can contain only onetag, which is in place in the default template. Theelement defines a document part. It takes an argument for the name. For example:

"rgChapter">

Look in thedocpart_templates.htmlfile in your template for some examples.

Edit HTML or PDF Styles in a Template

You can customize or add format styles in your HTML or PDF template. You edit the styles using cascading style sheets (CSS).

For HTML templates, you can use any CSS property or selector. For PDF, you can use a subset. SeePDF Style Sheets. You can also use XSL formatting objects (FO) to format elements in a PDF template. However, to simplify and streamline your code, use FO only for properties you cannot define using CSS.

  1. From the list of templates in the middle pane, select the template that you want to edit.

    Tip

    If the Report Explorer middle pane does not show a list of templates, then selectTools>Edit Document Conversion Template.

  2. In the Properties pane, clickOpen style sheet.

  3. In the HTML editor, edit the CSS.

    For information about editing a cascading style sheet, see documentation such as the W3Schools.comCSS tutorial.

  4. Save the style sheet.

See Also

Related Examples

More About

External Websites