Merge PDF
Audience:
Low-code EngineersSkill Prerequisites:
Tokens
Combines two PDF files into a new PDF. All pages of the first file come first, followed by all pages of the second file. The new file is saved in a portal folder, and its URL, path and file ID can be saved as tokens for the actions that follow.
The original files aren't changed.
This action requires the PDF feature to be licensed.
Typical Use Cases
- Add a standard terms and conditions PDF to the end of a generated contract or invoice
- Put a cover page in front of a report
- Combine several PDFs into one download, by running the action more than once and feeding each result into the next merge
Don't use it to
- Copy only some pages of a PDF. Use Extract PDF instead.
- Stamp one PDF on top of another, such as a letterhead or watermark. Use Overlay PDF instead.
- Merge files that aren't PDFs. Both files must be PDF documents.
Related Actions
| Action Name | Description |
|---|---|
| Generate PDF | Creates a PDF from an HTML template, which can then be merged. |
| Extract PDF | Copies selected pages of a PDF into a new file. |
| Overlay PDF | Draws the pages of one PDF on top of another. |
| Send Email | Sends the merged PDF as an attachment. |
| Delete File | Deletes the source files after merging, if they're no longer needed. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| First File | The PDF whose pages come first. Use one of the supported file identifiers. | Yes | empty string | Yes |
| Second File | The PDF whose pages are added after the first file. Use one of the supported file identifiers. | Yes | empty string | Yes |
| Folder | The portal folder where the new PDF is saved. Select a folder from the list, or switch to expression mode and enter a folder path relative to the portal root, for example Invoices/[Year]. The folder must already exist. | Yes | none selected | Yes |
| File Name | The name of the new file, without the extension. .pdf is always added, so Invoice-[OrderId] creates Invoice-1024.pdf. If empty, a random GUID is used as the name. | Yes | empty string | No |
Supported file identifiers
The files must be in the portal's file system.
| Format | Example |
|---|---|
| File ID | 77 |
| Path relative to the portal root | Documents/Terms.pdf |
| Path that includes the portal folder | /Portals/0/Documents/Terms.pdf |
| Absolute URL of a file on the site | https://example.com/Portals/0/Documents/Terms.pdf |
| LinkClick URL | /LinkClick.aspx?fileticket=... |
| Physical path inside the portal folder | C:\inetpub\site\Portals\0\Documents\Terms.pdf |
Output Parameters Reference
Each output parameter is the name of a token to create. Leave it empty if you don't need that value.
| Parameter | Description |
|---|---|
| Absolute URL | Token that stores the absolute URL of the new file, for example https://example.com/Portals/0/Invoices/Invoice-1024.pdf. |
| Relative URL | Token that stores the URL relative to the site root, for example /Portals/0/Invoices/Invoice-1024.pdf. |
| Physical Path TokenName | Token that stores the physical path of the new file on the server. |
| Link Click TokenName | Token that stores a LinkClick URL that downloads the new file. |
| DNN FileId TokenName | Token that stores the file ID of the new file. |
Considerations
- Existing files are overwritten. If a file with the same name already exists in the folder, it's replaced.
- A missing file is skipped, not reported. If one of the two files can't be found, the new PDF contains only the pages of the other file. If a file has no pages, it's skipped too. Check the identifiers if the result looks incomplete.
- Only two files per action. To merge more, run another Merge PDF that takes the previous result (for example its
DNN FileId TokenNametoken) asFirst File. - Password-protected PDFs aren't supported. There's no password parameter, so a PDF that needs a password to open can't be merged.
- Merging is done with the PDFsharp library. Pages are copied as they are, including their size and orientation.
Examples
To understand how to use the below examples, please see Running Examples.
1. Add terms and conditions to a generated invoice
This action appends Documents/Terms.pdf to an invoice whose file ID is in the InvoiceFileId token, for example one created by Generate PDF. The result is saved as Invoices/Invoice-<OrderId>.pdf, and its URL is saved in the InvoiceUrl token.
{
"Title": "Merge PDF",
"ActionType": "MergePdfs",
"Description": "Append terms and conditions to the invoice",
"Parameters": {
"FirstFileIdentifier": "[InvoiceFileId]",
"SecondFileIdentifier": "Documents/Terms.pdf",
"Folder": {
"Expression": "",
"Value": "/Invoices",
"IsExpression": false,
"Parameters": {}
},
"FileName": "Invoice-[OrderId]",
"AbsoluteUrlTokenName": "InvoiceUrl",
"RelativeUrlTokenName": "",
"PhysicalPathTokenName": "",
"LinkClickTokenName": "",
"FileIdTokenName": "MergedFileId"
}
}
After this action runs, [InvoiceUrl] can be used in an email, and [MergedFileId] can be passed to Send Email as an attachment.
Revised 09/26/2026