What this solution does
The 'Document Generator Pro' module automates file creation based on user-defined templates. The tool generates .docx files by inserting text, tables, and images into predefined fields.
To begin, prepare a template document in .docx format. Define variable names within this template that will be replaced with actual data during generation. Variable names must be enclosed in curly braces using Latin letters, for example: {COMP_NAME}. Place these variable fields in the required locations within the template and save the file.
Recommendation: When working on macOS, it is advisable to use MS Word for Windows to create templates.
The completed template can be uploaded to the system in two ways. First, upload the file to the desired folder via the 'Disk' menu in the portal. Second, use the Bitrix administrative section: navigate to 'Content' — 'Files and Folders', click 'Upload File', and specify the path to your template.
Add the 'Document Generator Pro' activity at any point in the business process. In the system interface, it may appear as 'Word Document from Template [mcart]'.
Open the activity settings. Specify the fields containing data to be inserted into the template's variables.
Title — the name of the activity. When multiple generators are used in a single process chain, this setting allows the resulting files to have unique names defined in each activity's configuration.
The 'Process fields in Merge Field format' checkbox must remain unchecked.
Template path — the location of the uploaded template file. Acceptable formats include a file path (e.g., /generator/template.docx) or a numeric ID (e.g., 523). If the field contains letters, the module treats it as a file path; if it contains digits, the module searches for a file with the specified ID.
The file path and name define the location and format of the output .docx document. You can specify the full path with the filename here, or provide only the filename and set the path separately in the fields below. Example: /generator/kp_{=System:Date}.docx — in this case, the filename will include the prefix kp, an underscore, and the current date. If only the filename is specified, such as kp_{=System:Date}.docx, the fields below must be filled in.
Disk ID — the identifier of the disk where the result file is saved. Instructions for obtaining the disk ID are provided below.
Folder ID on disk — the identifier of the folder for storing the result file. Instructions for obtaining the folder ID are provided below.
To substitute data into the template file, configure replacement rules for variables. In the action settings, specify the mapping: on the left, enter the variable name in the template; on the right, enter the source field name enclosed in curly braces. Select the field from the dropdown list using the button with an ellipsis.
If a field contains a list of values or does not display correctly, append the _printable suffix to the field name. For example, use {=Document:PROPERTY_TIP_OPLATY_printable} instead of {=Document:PROPERTY_TIP_OPLATY}.
After configuring all parameters, click the Save button in the Generator window, then save the changes to the business process using the button at the bottom of the page.
To view the disk ID in the Bitrix administrative panel, go to Settings — Tables. Select the b_disk_storage table, locate the required disk by name, and find its ID in the corresponding column.
In the Disk menu, select the required folder. An ID field will appear next to its name. If the field is missing, enable its display in settings.
To output a list of lines with line breaks, use special XML tags. For example, the w:br tag.
The inserted string must follow this format:
Item1 w:br Item2 w:br Item3
Adding a link to the generated file
It is often necessary to display a link to the created document. To do this, use the Download link for document activity Word Document from template value in Additional results.
The link can be displayed in Live Feed messages in two ways:
1. Using a tag: [url={=A14775_64625_42428_11813:Path}] link [/url]. The value {=A14775_64625_42428_11813:Path} is selected in Additional results as the value of the Download link for documents activity. This displays a clickable word link, which downloads the generated document when clicked.
2. Using a system variable: {=System:HostUrl}{=A14775_64625_42428_11813:Path}, where
Document Generator Pro by MC Art enables the creation of download links by inserting the value of the 'Download Document Link' activity into additional results. The generated link points to an HTTPS address containing the portal name and a path to a .docx file.
To generate a table of arbitrary size in the output file, follow these steps. First, design the table layout in the template file. In this example, the LIST field directs the generator to access string data from an array. The column name follows the dot. For instance, the field list.id populates data from the list[id] array row by row, representing the item number in the table.
Next, construct the data array. It must contain arrays for each field, such as [id], [fio], and [city]. The number of values in each column must be identical; otherwise, the table will be generated incorrectly.
Then, serialize the array using the serialize(your_array) function. If the serialized result is stored in the variable hostlist, the Generator parameters should be configured as LIST={=Variable:hostlist}. Finally, save the Generator settings.
Document Generator Pro
If a document field is a list, append the _printable suffix to the rule. If other field types do not display, also try using the _printable suffix.
For example: instead of {=Document:PROPERTY_TIP_OPLATY}, specify {=Document:PROPERTY_TIP_OPLATY_printable}.
PHP code example:
$rootA = $this->GetRootActivity();
$table_list=array (
"id" => array (1,2,3),
"fio" => array ("Ivanov Ivan Ivanovich", "Petrov Petr Petrovich", "Sidorov Sidr Sidorovich"),
"city" => array ("Chelyabinsk", "Vladivostok", "Perm")
);
$table_str=serialize($table_list);
$rootA->SetVariable("hostlist",$table_str);
If “Document Generator Pro” fits the task, General iT can install the module, configure it and verify the result in the project.