Main Content

mlreportgen.dom.TemplatePDFStyle Class

Namespace: mlreportgen.dom

Parse existing styles within PDF template

Since R2024a

Description

Use this class to create a Document Object Model (DOM) representation of an existing style in a PDF template. This class generates a style sheet entry in PDF style sheets only. HTML and DOCX template style sheets ignore this class. This class enables you to see what styles already exist in a template.

This class represents a PDF style defined by a PDF template (.pdftx) file. Opening a PDF template creates an array containing an instance of this class for each style defined by the template file. You can access the styles by using the TemplateStyles property of the style sheet stored in the Stylesheet property. Use this class to view and modify the CSS selector and formats for a PDF style. You can remove or replace PDF styles using the removeStyle and replaceStyle methods of the template style sheet.

The mlreportgen.dom.TemplatePDFStyle class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

example

style = TemplatePDFStyle(selector,rawFormats) creates an HTML style and sets the Selector and RawFormats properties to the values of selector and rawFormats, respectively. Use this constructor to define PDF styles that use more complex CSS selectors or formats that do not have equivalent DOM classes.

Properties

expand all

Name of the style as parsed from the value of the Selector property, specified as a character vector or string scalar.

Attributes:

SetAccess
private
NonCopyable
true

Data Types: char | string

CSS selector for the style, specified as a string scalar. This value includes the class name and element name. For example, a style that formats link elements, "exampleLink", would set the Selector property to "a.exampleLink". For information on the limited set of selectors supported by PDF style sheets: Modify Styles in PDF Templates. If the style sheet does not support the selector, the software throws an error.

Data Types: string

CSS properties and values of the style, specified as a string scalar. You must separate each CSS property and value pair by using a semicolon. For example, the Selector property for a style that formats color and font weight would be: "color:blue; font-weight:bold;".

Attributes:

NonCopyable
true

Data Types: string

The class ignores this property.

Tag for mlreportgen.dom.TemplatePDFStyle object, specified as a character vector or string scalar. The DOM API generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specify your own tag value to help you identify where to look when an issue occurs during document generation.

Attributes:

NonCopyable
true

Data Types: char | string

Object identifier for mlreportgen.dom.TemplatePDFStyle object, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object. You can specify your own value for Id.

Attributes:

NonCopyable
true

Data Types: char | string

Examples

collapse all

View an existing style in a PDF template, modify that style, and replace the existing style with the modified style.

Create a PDF Template and Examine the Default Styles

Create a new template based on the default PDF template, and examine the styles.

Import the DOM API namespace so you do not have to use fully qualified names.

import mlreportgen.dom.*

Create a template using the default PDF template.

t = Template("myTemplate","pdf");

Open the template and get the stylesheet.

open(t);
stylesheet = t.Stylesheet
stylesheet = 
  TemplateStylesheet with properties:

     TemplateStyles: [1×34 mlreportgen.dom.TemplatePDFStyle]
         TextStyles: []
    ParagraphStyles: []
       LinkedStyles: []
         ListStyles: []
        TableStyles: []
                Tag: 'dom.TemplateStylesheet:1901'
                 Id: '1901'

Modify Table of Contents Font

Modify the new template by changing the table of contents styles so that they use the Courier New font.

This pattern matches rules that start with "font-family:" and end with a semicolon.

pat = "font-family:" + wildcardPattern("Except",";") + ";";

Loop over all the template styles and change the matching styles to the Courier New font.

for style = stylesheet.TemplateStyles
    if startsWith(style.Name,"TOC")
        style.RawFormats = replace(style.RawFormats,pat,"font-family:""Courier New"";");
    end
end

Create a new style that sets link text in title paragraphs to bold.

newPDFStyle = TemplatePDFStyle("p.Title a","font-weight:bold;");
addStyle(stylesheet,newPDFStyle);

Close the template.

close(t);

Version History

Introduced in R2024a