> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flowforma.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Merge documents

> Use the Merge documents business rule to combine multiple PDF or Word files into a single document, with control over merge order and PDF security.

The Merge documents rule lets you merge the content of multiple documents (PDF or Docx) into a single document.

<img src="https://mintcdn.com/flowforma/29tXFCtk1ynp2c5R/images/product/creating-flows/business-rules/business-rule-types/communications-rules/merge-documents/merge-documents-1.png?fit=max&auto=format&n=29tXFCtk1ynp2c5R&q=85&s=a3d6ef32263c5792f8c5500e4d368682" alt="Merge documents rule configuration" width="620" height="1053" data-path="images/product/creating-flows/business-rules/business-rule-types/communications-rules/merge-documents/merge-documents-1.png" />

## Title

The first part of the business rule lets you define a **title** for your rule, and then select the event on which the rule should operate. The default title of the rule is the standard **FlowForma** rule name. You can change this by deleting the text and entering your own.

In the **event** field you determine when the rule is executed. For a flow this can occur when the form is loaded, started or completed. For a step this can occur when the step is started, saved or completed. For questions it can occur when the question is updated.

## Rule condition(s)

The second part of the business rule lets you set conditions. These are not required, but if entered, they control when the rule is executed in relation to other items in the form.

## Rule actions

* **Document type**: pick the type of documents that will be merged.

* **SharePoint document URL's**: enter the URLs of where the documents you want to merge are stored.
  * The inputs for this can either be:
    * A manually entered URL to the document
    * A question in the form (file upload, multiple file upload, single/multiple line of text with a URL to the document)
    * Rules that output documents (generate document, generate multiple documents)

<Warning>
  **Note**: the order of the URLs is the order they are merged into the single output document. It can be rearranged by dragging and dropping the grid icon on the left into the preferred location.
</Warning>

* **SharePoint folder**: by default, the newly created document is saved in the form folder in the "[Form Documents](/product/form-documents)" library. This field lets you define a different SharePoint folder for saving documents.

## Available Tokens

The **Available Tokens** let you specify a folder structure, including sub-folders, for storing documents. By default the Form Documents library is used, and as documents are generated they are placed into a sub-folder for each **Form Title**.

You may instead wish to create a sub-folder in the Form Documents library for each flow, so that when you go to the Form Documents library, you see a folder for each flow (provided a document generation rule has executed and created that folder).

You can create more sub-folders using, for example, the Step Title token - so when you go to the Form Documents library, you open the relevant Flow Title folder, open the relevant Step Title folder, and all documents generated by that step, in that flow, are stored there.

A few examples:

Sub-folder for Flow Title - [https://sitename.com/sites/FlowFormaSite/FormDocuments/{FlowTitle}](https://sitename.com/sites/FlowFormaSite/FormDocuments/%7BFlowTitle%7D)
Sub-folder for Step Title - [https://sitename.com/sites/FlowFormaSite/FormDocuments/{StepTitle}](https://sitename.com/sites/FlowFormaSite/FormDocuments/%7BStepTitle%7D)
Sub-folder for both Flow Title, and Step Title - [https://sitename.com/sites/FlowFormaSite/FormDocuments/{FlowTitle}/{StepTitle}](https://sitename.com/sites/FlowFormaSite/FormDocuments/%7BFlowTitle%7D/%7BStepTitle%7D)

The following tokens are available for the folder path: `{FormID}`, `{StepID}`, `{FlowTitle}`, `{StepTitle}`, `{FormTitle}`, `{FlowFormaUrl}`, `{FlowFormaParentUrl}`, and `{FlowFormaSiteCollectionRoot}`. The `{FlowFormaUrl}`, `{FlowFormaParentUrl}`, and `{FlowFormaSiteCollectionRoot}` tokens only resolve when the folder is on the FlowForma site.

* **Replace tokens using folder format**: certain characters can be replaced with underscores; this option prevents that from happening when replacing tokens.

* **Overwrite document**: if a document already exists in the destination folder, checking this option overwrites the original document with the new one. If left unchecked, an incrementing number is added in parentheses (e.g. myDocument.pdf (1)).

* **Open document in new tab**: if checked, the merged document opens in a new browser tab.

* **Attach to step**: check this box if you want to access the newly created document directly from the form, without having to go to the SharePoint library where the document was saved. To use this option, you must also check the "enable attachments" option at the step definition level. A link to the document is included on the form.

* **PDF security**: lets you set security on the PDF documents, so a password must be entered to open the document. See PDF security for more details.

* **Do not use automatic naming**: by default, the name of the created document is "form+form ID". The form ID is a number incremented from 1 each time a new form is created.
  You can decide not to name documents this way, and instead define a new name using the document suffix.

* **Document suffix**: if you specify a suffix, it is added after the form ID. The new name of the document will be "form+formID+suffix", unless "do not use automatic naming" is enabled, in which case the document name will be only what is entered as the suffix.
  It supports the following tokens:
  * **StepCode|QuestionCode**: returns the value of a question. If a question is reused on multiple steps, you can enter the step code to specify which step to take the value from, along with the question's question code.
  * **QuestionCode**: returns the value of a question
  * **FormStarted**: returns the date and time the form was started
  * **FormCompleted**: returns the date and time the form was completed
  * **FormAuthor**: returns the name of the person who created the form
  * **FlowTitle**: returns the title of the flow the form was generated using
  * **ID**: returns the ID of the form

* **Stop execution**: if stop execution is enabled and this rule is executed, no other rules are executed.

* **Enabled**: as rules are not saved to a list the way questions and steps are, if you want to stop a rule executing without deleting it, you can toggle this option to enable/disable the rule.

* **Enable audit**: if checked, a record is added to the audit trail when this rule is executed. This option is available when the Compliance feature pack is activated.
