Writing an Expression to Download a Dynamic Document

The DocumentDownload function can be used to download a PDF document based on a dynamic document item.

The function's syntax is as follows:

DocumentDownload( InstructionType, DocumentKeyword, ModelName, WatermarkText, WatermarkColour, WatermarkFontSize, WatermarkFont, ActionKeyword );

InstructionType is an integer or string that determines which of the available instructions is activated by the function.

DocumentKeyword is a string containing the keyword of the dynamic document item you want to use.

To merge more than one document into a single PDF, use the InsertTemplate function to create a Document Pack.

ModelName is a string containing the keyword of the model that hosts the chosen document item. If this argument is omitted or given an empty string, the function will attempt to locate the document in the main model.

WatermarkText is a string containing the text you want to appear as your watermark. If this parameter is not given a value, no watermark will be added.

WatermarkColour is a string containing the name of the colour you want to apply to the watermark, such as "Red", "Blue", or "Black". If omitted or left as an empty string, the watermark will default to light grey.

You can find a complete list of valid colours by referring to this MSDN web page.

WatermarkFontSize is an integer representing the point size of the watermark's font. A decimal point can be used if required. The default font size for a watermark is 100.

WatermarkFont is a string containing the name of a valid font for the watermark. If it is omitted or left as an empty string, or if the person viewing the file does not have the specified font installed, the watermark will be shown in Times New Roman.

ActionKeyword is a string containing the keyword of an action that will run after the document has been downloaded.

The following expression demonstrates how to use the DocumentDownload function to generate a PDF based on a dynamic document item named MonthlyProfitReport:

DocumentDownload( 2, "MonthlyProfitReport" );

If the document item was located in a sub-model named DocumentRepository, you would need to update the expression as follows:

DocumentDownload( 2, "MonthlyProfitReport", "DocumentRepository" );

To add a blue, 120pt watermark of the word "DRAFT" in Arial font, change the expression to the following:

DocumentDownload( 2, "MonthlyProfitReport", "DocumentRepository", "DRAFT", "Blue", "Arial", 120 );

Finally, to run an action called ShowNewGroup after the download has completed—redirecting the user to a different question group—change the expression to the following:

DocumentDownload( 2, "MonthlyProfitReport", "DocumentRepository", "DRAFT", "Blue", Arial, 120, "ShowNewGroup" );