Main Content

Modify Styles in PDF Templates

You can customize or add format styles in your PDF template. For information on properties you can use in PDF style sheets, see PDF Style Sheets.

  1. In the unzipped template, navigate to TEMPLATEROOT/Stylesheet.

  2. In a text or HTML editor, edit the cascading style sheet CSS file for the styles you want to create or modify.

    For information about editing a cascading style sheet, see CSS tutorial on the W3 Schools website.

  3. Save the style sheet.

Use the style sheet to define global styles, that is, the appearance of your template elements. You define PDF styles primarily using a subset of cascading style sheet (CSS) formats. Using a style sheet for the default formats simplifies your program. You also make fewer updates when your formatting changes. Format elements in your DOM program when you want to override the default format for an instance. For example if you want the set the document text font size to 12pt but the text of the first paragraph set to 16pt, use the stylesheet to set the overall document font-size and override that default size using the Style property of the first paragraph .

Note

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. For information about FO, see https://www.w3.org/TR/xsl11/#fo-section.

Supported CSS Formats

These CSS formats are supported:

Supported CSS FormatsSupported Custom CSS formats
  • background-color

  • border

  • border-bottom

  • border-bottom-color

  • border-bottom-style

  • boder-bottom-width

  • border-color

  • border-left

  • border-left-color

  • border-left-style

  • border-left-width

  • border-right

  • border-right-color

  • border-rigtht-style

  • border-right-width

  • border-style

  • border-top

  • border-top-color

  • border-top-style

  • border-top-width

  • border-width

  • color

  • counter-increment

  • counter-reset

  • font-family

  • font-size

  • font-style

  • font-weight

  • height

  • line-height

  • list-style-type

  • margin

  • margin-bottom

  • margin-left

  • margin-right

  • margin-top

  • padding

  • padding-bottom

  • padding-left

  • padding-right

  • padding-top

  • text-align

  • text-decoration

  • text-indent

  • vertical-align

  • white-space

  • width

  • page-border

  • page-border-color

  • page-border-width

  • page-border-style

  • page-border-margin

  • page-border-bottom

  • page-border-bottom-color

  • page-border-bottom-width

  • page-border-bottom-style

  • page-border-bottom-margin

  • page-border-left

  • page-border-left-color

  • page-border-left-width

  • page-border-left-style

  • page-border-left-margin

  • page-border-right

  • page-border-right-color

  • page-border-right-width

  • page-border-right-style

  • page-border-right-margin

  • page-border-top

  • page-border-top-color

  • page-border-top-width

  • page-border-top-style

  • page-border-top-margin

  • page-border-surround-header

  • page-border-surround-footer

  • page-margin

  • page-margin-top

  • page-margin-left

  • page-margin-bottom

  • page-margin-right

  • page-margin-header

  • page-margin-footer

  • page-margin-gutter

  • page-size

  • page-width

  • page-height

  • page-orientation

  • halign

  • valign

Selectors and Selector Combinators

You can use these selectors and selector combinators in a CSS sheet:

  • Universal selector (*)

  • Type selector (for example, p or span)

  • Class selector (for example, p.MyPara)

  • Descendant combinator (space)

  • Child combinator (>)

  • Adjacent sibling combinator (+)

  • General sibling combinator (~)

Note

You can use the generalized sibling (~) and adjacent sibling (+) selectors only when creating the report in memory. If you are using streaming mode, do not use these selectors.

Selector Pseudo-Classes

Since R2025a

To dynamically style document elements based on their hierarchical position in a PDF report, you can use these selector pseudo-classes:

  • :empty — Element has no children

  • :first-child — Element is the first child of its parent

  • :first-of-type — Element is the first element of its type in parent

  • :last-child — Element is the last child of its parent

  • :last-of-type — Element is the last child of its type in parent

  • :nth-child(an+b) — Element is the Nth child of its parent

  • :nth-last-child(an+b) — Element is the Nth child of its parent, with indices counting from the last child

  • :nth-last-of-type(an+b) — Element is the Nth child of its type in parent, with indices counting from the last child

  • :nth-of-type(an+b) — Element is the Nth child of its type in parent

  • :only-of-type — Element is the only of its kind in parent

  • :only-child — Element is the only child of its parent

For pseudo-classes that use (an+b) indexing:

  • a — Specifies the interval at which the elements are selected

  • n — Is a counter starting from zero and increments by one when N is positive and decrements by one if N is negative

  • b — Specifies the starting point of the count

    Note

    :nth-last-child(an+b) and :nth-last-of-type(an+b) count from the last element rather than the first element.

For example, to style the even rows in a table, enter:

tr:nth-child(even) {
    background-color: #f2f2f2;
}
To style every third paragraph element from the end, starting with the first paragraph from the end, enter::
p:nth-last-of-type(3n+1) {
    background-color: lightblue;
}
For more information on CSS pseudo-classes, see CSS Pseudo-classes Reference on the W3 Schools website.

Hyphenation Styles in PDF Templates

You can enable or disable hyphenation for paragraph and table cell styles that you define. You can also specify a hyphenation character. Alternatively, you can specify hyphenation on an instance of a <p> or <td> element.

Specify Hyphenation for PDF Styles

You can specify hyphenation when you define a paragraph or table cell style. Use the hyphenation style with the name of the hyphenation character (hyphen or space), or use none to turn hyphenation off. If your style does not specify hyphenation, hyphenation is off by default for paragraphs and on by default for table cells, using a space character. These examples show the possible values for defining hyphenation in your CSS:

  • p.Style1 { hyphenation: hyphen; }

  • td.Style2 { hyphenation: space; }

  • p.SentenceStyle { hyphenation: none; }

Specify Hyphenation in PDF Tags

You can use a hyphenation value with the style attribute of paragraph and table cell styles. Use the value in the form hyphenation:hyphenStyle;, where hyphenStyle is none, hyphen, or space. For example:

<p style="hyphenation:hyphen;">Paragraph text</p>

If you do not specify the value, or hyphenation is not specified in the CSS, the default is no hyphenation for paragraphs and table cells.

See Also

Classes

Topics

External Websites