Using a Field to Reference an Image

Among the various types of Field that can enhance the content of a dynamic document, there is one that uses the Image function to display a specific image. Images displayed using this function can come from a variety of sources, including:

  • An Image Item associated with the document that contains the field. You cannot use the field to display an image from one document inside another.
  • A Shared Image Item associated with the document's repository.
  • The URL or File Path of an image file accessible to your KnowledgeKube repository. This includes files accessible via the internet.
  • The encoded Base64 Binary String of an image. This can be obtained, for example, from images uploaded using a KnowledgeKubeFile Uploader.

The function used by this field requires a number of arguments to determine the source of the image and how it will look when the host document is generated.

The syntax of the Image field is as follows:

~~Image( ImageName, ImageType, ImageOptions, ImageWidth, ImageHeight, ImageData )~~

If you want the field to display an image using a base64 binary string, the ImageName parameter must be left blank and the ImageData parameter must be given an argument. Otherwise, the reverse is true: ImageName must be given an argument and ImageData must be left blank. The ImageOptions, ImageWidth, and ImageHeight parameters are optional, no matter what type of image you want to display.

As with all types of dynamic document field, a parameter with no argument must be left completely blank, with nothing appearing between the commas that separate it from its adjacent parameters.

The value assigned to ImageName will depend on where the chosen image is stored:

  • Image Item or Shared Image Item - Write the name of the image item, as it appears in the KnowledgeKube back-office tool.
  • Website or Network Directory - Write the complete URL or file path of the external image. Due to the way Azure Remote App refers to your personal computer, you will need to preface any file path that references your local machine with \\tsclient\. For example, \\tsclient\C\MyDocuments\Image.png.

The ImageType argument tells the function what type of file you are trying to display. This must be set to either jpeg or png.

The ImageOptions parameter tells the function how to access the specified image. The following is a list of valid arguments for this parameter, including the type of image each one refers to:

  • 1 - Use an Image Item or Shared Image Item created using KnowledgeKube. If you omit the argument, this option will be used by default.
  • 2 - Use an external image stored on a Website or in a Network Directory.
  • 3 - Use an encoded Base64 Binary String based on the image. This string must be stored in an identifier. One method of obtaining this is to upload the image using a File Uploader, then extract its binary string using the GetUploadedDocumentBinaryString function.

If you use option 3 for the ImageOptions argument, you will need to use the ImageData parameter to specify which identifier holds the binary string.

The ImageWidth and ImageHeight parameters let you override the image's default dimensions, as measured in pixels.

ImageData is the name of the KnowledgeKube variable that contains the encoded base64 binary string of the image you want to display. Only use this parameter if the value of your ImageOptions parameter is 3.

A valid example of the Image field is shown below:

~~Image(https://smilingbag.files.wordpress.com/2013/10/smiling-bag-logo.png, png, 2, 200, 200)~~

This example will cause the logo found at the specified URL to appear when the document is rendered. Because the file type is png, we've specified that as the second argument. The third argument's value of 2 specifies that the file is found at an external network location (in this case, the internet). We've specified custom dimensions of 200 x 200 pixels to override the image's regular width and height. Lastly, because we're not using a base64 binary string, the ImageData parameter has been omitted.

The linked image, as it is rendered by the sample Image field above.

You can replace any of the arguments with a variable keyword. If the specified keyword exists, the function will use its value for the argument. If the keyword does not exist, it will use the literal value instead.

You can also replace one or more of your Image field's parameters with aliases from a data source. Doing this lets you populate the parameters with values from specific data source fields, then use the ForEachDataSourceRow document function to display an image corresponding with specific rows in your data source. For example, if you have a data source that includes a column of image URLs, you could use that column's alias as the field's ImageName argument. When the resulting table is generated in your document, each image will be drawn from the URL in the respective data source row.