Replaces placeholder variables by fragments of Word.

public void replaceVariableByWordFragment(HashMap<String, WordFragment> variables)
public void replaceVariableByWordFragment(HashMap<String, WordFragment> variables, OptionsReplaceVariableByWordFragment options)

This powerful method allows the substitution of placeholder variables by Word fragments that may include:

  • formatted text
  • tables
  • images
  • footnotes
  • name it!

This method offers you complete control over the contents of the generated Word document. Moreover it is fully compatible with the PDF conversion plugin.

The Word fragments should be instances of the WordFragment class.



This must be a HashMap with the names of the placeholder template variables as keys and the WordFragment instances that should replace them as values.


Option Type Description
firstMatch Boolean If the variable appears more than once within the Word document and firstMatch is set to true, Javadocx will only replace the first ocurrence of the variable within the Word document.
target String Possible values are: document (default), header, footer, footnote, endnote, comment. This option sets the scope of the replacement procedure.
type String Possible values are:
  • block (default): replaces the variable and removes its containing paragraph.
  • inline: only replaces the variable by the WordFragment inline content (it may be used to replace a variable by formatted text).
Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like: