logo
Documents
Nov 16

Conditionally generate and combine documents into one PDF

Customer Support Engineer

A contract package can contain a main agreement and standard terms, with an NDA included only when confidential information will be shared. For example, an IT services company might need an NDA when accessing a customer's internal systems, but not for standard services.

In this tutorial, we'll generate the documents from the same data and combine the required documents into one PDF using Plumsail Documents.

Illustration of a merged PDF contract package containing a service agreement, terms and conditions, and an optional NDA  

In this article:

Prepare the contract templates and data

Download the three templates for this example:

  • Service agreement: customer details, contract reference, scope, and commercial terms. Always included.
  • Terms and conditions: standard terms that accompany every agreement. Always included.
  • NDA: confidentiality provisions. Included only when the input data requests it.

To use {{includeNda}} in the template condition, we've added the {{includeNda}} token to the NDA title as hidden text. This way, the field can be used in the condition without appearing in the generated document. To see or edit it in Word, enable the display of hidden text.

Hidden token in the NDA template  

Create a Process with multiple templates

Log in to the Plumsail Documents account and create a new process. We can upload our own template, start with a blank document, or choose one of the ready-to-use templates.

To reproduce this example, select Upload a document and upload one of the downloaded templates, for example, Service agreement.

Create a process and upload a template  

Name the process Generate contract package, leave the template's output file type as DOCX, and click Create. Later, we'll select Merged PDF in the Process settings. This automatically converts the generated documents to PDF and combines them into one file, so we can keep the DOCX output format for all three templates.

Process name and settings  

Add two more templates and change their settings

By default the first template is named after the Process name. In our case it's "Generate contract package". Let's rename the template so it’s easy to identify in the Process panel.

Click Settings above the template editor. Alternatively, hover over the template in the Process panel and click its gear icon. Enter Service agreement under Template name and save.

Rename service agreement in the process settings  

Next, add two more templates, Terms and conditions and NDA, to the created process.

Click + beneath the first template in the Process panel and select Add template.

Add more templates  

Upload the Terms and conditions template, enter Terms and conditions under Template name, and click Create.

Add terms and conditions template  

And then add the third template, NDA, rename the template and click Create.

Add NDA template  

Conditionally generate the NDA

Open the NDA template settings and enable Conditionally run template.

Select includeNda and set the condition to Equals true. The token is hidden in the document because it controls whether the NDA is generated; its value does not need to appear in the contract package. Save the NDA template settings.

NDA conditional settings  

Combine the generated documents into one PDF

Next, configure the Process to convert and combine the generated documents into a single PDF.

Click the gear icon next to the Process heading in the left panel. This opens Process settings, where we can configure the output for the entire contract package.

Under Output files, select Merged PDF and enter the following output filename:

Contract package {{contractNumber}} {{includeNda|bool(with, without)}} NDA from {{@date|format(yyyy-MM-dd)}}

The filename uses three tokens:

  • {{contractNumber}} adds the contract reference from the input data.
  • {{includeNda|bool(with, without)}} uses the bool function to return with when includeNda is true and without when it is false.
  • {{@date|format(yyyy-MM-dd)}} uses the format function to include the generation date without the time.

For example, running the Process produces one of these filenames depending on the date and NDA:

  • Contract package CTR-2026-1042 with NDA from 2026-11-10.pdf
  • Contract package CTR-2026-1042 without NDA from 2026-11-10.pdf

This makes the two versions easy to distinguish before opening the attachment. Click Save to apply the settings.

Process settings  

The result will contain the service agreement and terms and conditions. The NDA will be included only when includeNda is true. When the condition is not met, the NDA is skipped and the remaining documents are combined into the PDF.

For this case we switched the Process mode to Production. It removes a Plumsail watermark from the result but the runs are charged. You can keep the Process in Test mode while checking the results.

Deliver the contract package

Now let's add a delivery. We'll use an Email delivery which sends the completed contract package to the customer for review. The merged PDF will be attached to the message.

Click + beneath the templates in the Process panel, select Add delivery.

Add delivery  

Then choose Email.

Select Email delivery  

Click SMTP settings, enter the connection details supplied by the email provider, and click OK.

Email delivery SMTP settings  

Once connected, configure the message.

Use the { } token picker to insert values from the Process data into the recipient, subject, or body. The customerEmail field determines who receives the package. Save the delivery settings.

Email delivery settings  

Each run sends one PDF. It contains the service agreement and terms and conditions, plus the NDA when includeNda is true.

Run the Process and check both results

Now, let's run the entire Process twice with the same contract data: first with the NDA included, then without it.

Generate a package with an NDA

Click the Start button at the top of the Process panel. Select Submit custom JSON data, paste the sample JSON, and start the Process.

Also replace purchasing@example.com in customerEmail with your own email address.

{
  "contractNumber": "CTR-2026-1042",
  "agreementDate": "2026-11-02",
  "customerCompany": "Contoso Ltd",
  "customerAddress": "123 Example Street, London, UK",
  "customerEmail": "purchasing@example.com",
  "projectName": "Customer portal implementation",
  "serviceDescription": "Configure and launch a customer portal, including setup and user training.",
  "contractValue": 5000,
  "currency": "USD",
  "includeNda": true,
  "jurisdiction": "England and Wales"
}

Here, includeNda is true, so it matches the condition configured for the NDA template. Click Start to submit the data and run the Process.

Run with NDA  

Once the run finishes, open the email and its PDF attachment. Check that the package contains all three documents: Service agreement, Terms and conditions, and NDA.

Result with NDA  

Generate a package without an NDA

Open Submit custom JSON data again and use the following example. It differs from the first one only in the value of includeNda, which is now false.

{
  "contractNumber": "CTR-2026-1042",
  "agreementDate": "2026-11-02",
  "customerCompany": "Contoso Ltd",
  "customerAddress": "123 Example Street, London, UK",
  "customerEmail": "purchasing@example.com",
  "projectName": "Customer portal implementation",
  "serviceDescription": "Configure and launch a customer portal, including setup and user training.",
  "contractValue": 5000,
  "currency": "USD",
  "includeNda": false,
  "jurisdiction": "England and Wales"
}

In this case the NDA condition is no longer met, so the Process skips that template. Open the new email attachment and check that it contains only the Service agreement and Terms and conditions, with no NDA pages.

Result without NDA  

Run the Process automatically

You can also connect the Process to your business workflow through Plumsail Documents integrations and generate a package when a deal is marked as won in your CRM or when a customer submits a form.

Set up the trigger or schedule with Power Automate, Make, or Zapier. Retrieve the customer and contract details from your source app and pass them to the Process.

Create a conditional contract package

We've built one Process that generates a contract package, includes an NDA when needed, and emails the combined PDF to the customer.

To try this workflow with other templates, start with Plumsail Documents or book a call with our sales team for a demo session.