# Merge Subdocuments into Document

### Overview

This procedure takes multiple subdocuments (typically document fragments, sections, or extracted portions) and combines them into a single merged document. Each subdocument maintains its original content and order, creating a complete document from multiple subdocument files.

{% hint style="info" %}
Make sure to add the **Document Processing Book** to your agent before using this automation procedure.
{% endhint %}

### Syntax

Below is a line-by-line overview of the automation syntax. Expand each line to learn more.

<details>

<summary><code>merge subdocuments into document</code></summary>

#### What does it do?

Begins the subdocument merging process.

#### Where does it go?

This phrase should be written on a **new line**.

#### Is it required?

✅ Yes — This phrase is **required**.

#### Does it require data?

✅ Yes — Use this phrase to start merging subdocuments.

#### Example

```
merge subdocuments into document
```

</details>

<details>

<summary><code>the subdocuments are {subdoc_list}</code></summary>

#### What does it do?

Specifies the list of subdocuments to merge.

#### Where does it go?

Indented under `merge subdocuments into document`.

#### Is it required?

✅ Yes — This phrase is **required**.

#### Does it require data?

✅ Yes — Replace {subdoc\_list} with a reference to a list of subdocuments.

#### Example

```
the subdocuments are the extracted sections
```

</details>

<details>

<summary><code>the document name is {name}</code></summary>

#### What does it do?

Specifies a custom name for the merged document.

#### Where does it go?

Indented under `merge subdocuments into document`.

#### Is it required?

❌ No — This phrase is **optional**.

#### Does it require data?

✅ Yes — Replace {name} with your desired filename (with or without extension).

#### Example

```
the document name is "complete_report.pdf"
```

</details>

### Examples

#### 1. Merge Extracted Subdocuments

Merges subdocuments that were previously extracted from a larger document.

```
merge subdocuments into document where
    the subdocuments are the extracted sections
    the document name is "complete_report.pdf"
```

#### 2. Merge Subdocuments with Auto-Naming

Merges subdocuments using an automatically generated document name.

```
merge subdocuments into document where
    the subdocuments are the subdocument files
```
