Skip to main content
Skip table of contents

Richtext Styles

Structure

{mainTitle}

{subTitle}

empty or {content}

Behavior

Richtext nodes are produced by filling out a word table template with main title, subtitle and html content. The tags in the html fragment can optionally be translated to word styles. The configuration of this mapping happens like this:

  1. If the html element has a class defined, it is used as the word style

  2. The mapping defined in the style’s metadata is used

  3. The mapping defined in application.properties is used

  4. If none is provided, the Aspose.Words mapping is applied

The application.properties entries look as follows:

richtextnode.htmltagmapping.<html tag>=<name of word style>

Example:

richtextnode.htmltagmapping.h1=Header1

If no style is specified, the content is produced inline without a style. The rules for translating the HTML above still apply though.

If a style is defined, the HTML content is produced in the cell with a {content} placeholder or if there is none, the first empty cell is used.

Metadata

The metadata has the following structure:

CODE
{
  "default": true,
  "htmlTagToWordStyle": {
    "h1": "P_H1",
    "h2": "P_H2"
  }
}

In addition to defining default styles it is possible to define a HTML tag to Word style mapping. The following HTML tags are supported:

  • h1-h6

  • p

  • ul

  • ol

Examples

Example 1: Showing a simple case with a style

template-richtext_simple.docx abstract-report-richtext_simple.json output-richtext_simple.docx

Example 2: Showing what happens if no style is specified

output-richtext_no_style.docx abstract-report-richtext_no_style.json template-richtext_no_style.docx

Example 3: Showing how to specify a word style in HTML by using classes

template-richtext_html_class_style.docx abstract-report-richtext_html_class_style.json output-richtext_html_class_style.docx

Example 4: Showing how the mapping in the metadata works

template-richtext_metadata.docx output-richtext_metadata.docx abstract-report-richtext_metadata.json

Example 5: Showing how the mapping in the configuration file works

abstract-report-richtext_config.json application.properties template-richtext_config.docx output-richtext_config.docx

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.