Generate Property Risk Report from Template

The template shows how to achieve color-coded risk ratings by conditionally coloring table cells.

Example in detail

This example exists primarily to show the bgcolor attribute.

Tables are used to lay out the information, with a placeholder image inserted into one of the table cells.

A dynamic table with repeating rows is used in the body of the report to show the property's color-coded risk ratings.

Adding a dynamic image

This template uses a placeholder image in the top right corner.

The placeholder image in the template is replaced by a photo of the property when the document is generated. Refer to the article Images  to understand placeholder images.

Images can be provided in one of two ways:

  • entirely by the data
  • stored, and then selected by supplying just the name of the image in the data.

This example uses the second approach, which is called a "stock" image. The "property.png" file has been previously stored and only the name of the image is sent in the data.

For more detail on sending or storing image files, refer to the article How to send image data or retrieve images from a file or URL.

Adding a dynamic table

To see the structure of the "risk ratings" table, select the table, then choose View Gridlines in the Layout ribbon tab.

 The <<rr_  and <<er_ directive is used to loop through the propertyAspects array, displaying the risk information associated with each aspect of the property.

For further information on using the <<rr_ directive, see Tables.

Disabling alternating row coloring

By default, Docmosis will apply alternating table row colors whenever a row inside a set of repeating rows has a different background color to that of the starting row with the <<rr_ directive. See Alternating row colours.

To disable the alternating rows effect on the "risk ratings" table, the directive <<noTableRowAlternate>> is used.

By disabling alternating rows, the navy background for the <<aspect>>, and a white background for the <<comment>> is maintained.


Assigning the bgcolor

The html-like bgcolor attribute is used to define the background color of table cells.

  • The bgcolor attribute defines colors using 6-digit hex codes.
  • The bgcolor is assigned to a variable in code above the table.
  • The bgcolor attribute can only be applied to individual table cells.

Here is the syntax for assigning the bgcolor variables, and then setting the table cell colors as determined by the data in each row of the propertyAspects array.

  1. Above the table, create a new variable called $green and assign a bgcolor with the hexadecimal value for green:
  2. Similarly, create the variables $yellow, $orange, and $red and assign a bgcolor to each of these, where the hexadecimal value for the bgcolor corresponds with the variable's name (yellow hexadecimal value for $yellow, and so on). 


Within the table, repeating rows are used to loop through the propertyAspects array. Each row is evaluated for its rating, and each of the four cells will be assigned its specified background color if its condition is met. The actual code used to conditionally color the table cells is concealed in the highlighted cells below. 


Note: The code contained in "Cell 1" looks like this, with variations of the same code in "Cell 2", "Cell 3", and "Cell 4":

  1. In the table, use repeating rows to loop through the propertyAspects array: 
    <<rr_propertyAspects >>...<<er_>>.
  2. Within the repeating loop, carry out these steps for "Cell 1":
    1. Assign an initial value of null to the $color variable: <<$color=''>>
    2. If the rating for this row = low, update the $color variable to the value in the $green variable: 
    3. Display the $color variable in the cell: <<$color>>
      If $color is still null (the condition is not met) then there is no background color. If $color is $green, then it is <bgcolor="#33CC33"/> and this results in a green background color for this cell.
  3. Still within the repeating loop, carry out similar steps for the contents of "Cell 2", "Cell 3", and "Cell 4".
    1. For "Cell 2" give the cell a background of yellow if the rating is mild:
    2. For "Cell 3" give the cell a background of orange if the rating is moderate:
    3. For "Cell 4" give the cell a background of red if the rating is high:

Viewing and editing the contents of a table cell

To view the code inside a cell, copy the cell contents and paste the text into a text editor, such as Notepad.

  • To copy a cell's contents: select the cell, then choose Select Select Cell in the table's Layout ribbon tab, and press Ctrl+C to copy.

Choosing colors and hex values in Microsoft Word

To change the background color of a table cell and find out the color's hex value, select the cell, click the Shading button on the Home ribbon tab, then select More Colors.

This opens the Colors window.

To select a standard color, click on a color hexagon in the Standard tab's color palette, then click OK to save it.

To choose a custom color, and to see the hex value, open the Custom tab. 

The Hex value for the custom color can be copied and used for the bgcolor. The value changes when a different custom color is chosen.

  • Click on a color in the palette to choose it.
  • To adjust the selected color's tinting or shading, move the slider up or down.

To apply the custom color, click OK.

Note: Alternatively, type or paste a known hex value into the Hex edit box, then click OK to apply the custom color.

The new color is applied to the  table cell.


Invalid Input

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam. Please also consider contacting if you need help with this article.

Sorry, this field will only accept letters and numbers, and not special characters, to limit spam.

Invalid Input

Document Gallery

Docmosis showcases its template-based document generation capabilities through a gallery of downloadable PDF documents. The gallery features a mixture of real documents provided by customers as well as links to PDFs generated from example templates, desgined to illustrate the versatility of Docmosis.