Practical javadocx

HTML and CSS

Introduction

One of the most remarkable features of javadocx is the possibility of working directly with HTML and CSS to create contents.

Just define the HMTL code and its styles and you will get a Word format conversion with great quality and similarity with the original code.

HTML and CSS to WordML

embedHTML is the method to add HTML to a document:

In the html parameter, write the HTML and CSS you want to transform to WordML; either the styles in the head or inline in the tags. The second parameter, options, sets the options. The most important options are:

  • isFile: It's a boolean to set if the HTML is in a file. By default, it is a string.
  • downloadImages: Boolean to download the images.
  • wordStyles: HashMap to associate to a class or id Word styles. It must be used along with the strictWordStyles option of this same method.

For example, to add a HTML code with inline styles:

Replacing variables in templates

When working with a template, replaceVariableByHTML allows to replace a placeholder with HTML:

This HTML code is transformed into a WordML before replacing the placeholder.

The available parameters are:

  • var: Name of the placeholder
  • type: block or inline
  • html: HTML to be transformed
  • options: It has the same available options as the embedHtml method

After loading the template, an easy replacement would be:

This code changes the placeholder VAR by a paragraph with the text javadocx.

Tips and tricks

When adding HTML with images, it is advisable to enable the option downloadImages. It is important too to make sure that the paths are defined as absolute instead of relative.

Next - Sections and properties