Skip to main content

Merge Word Documents in Power Automate

What this action does

PDF4me, Merge Documents combines multiple Word files (DOCX/DOC) into a single merged document inside your Power Automate flow. Control the merge order with SortPosition, choose how styles are handled (KeepSourceFormatting, UseDestinationStyles, KeepDifferentStyles), and set the OOXML compliance level. Pull documents from SharePoint, OneDrive, Dropbox, or email, the output is a clean, single DOCX ready for distribution or further processing.

Related Blog Posts
No blog post yet for this feature — coming soon.
In the meantime, browse the PDF4me blog for tutorials and workflows across every platform.
Visit the blog

Authenticating Your API Request

Every PDF4me action in Power Automate requires a valid connection. Enter your PDF4me API key when you add the action for the first time, it is reused automatically in all subsequent PDF4me actions in the same flow.

Important Facts You Should Not Miss

SortPosition controls the merge order
Each document in the array needs a SortPosition value. Documents merge in ascending order, position 0 becomes the base document. You can use any numbering scheme (0, 1, 2 or 10, 20, 30). When pulling files from a loop, dynamically assign SortPosition using the iteration index so the order is always deterministic regardless of how files are retrieved from storage.
FormatMode determines how styles are reconciled
KeepSourceFormatting (default) preserves each document's own styles. UseDestinationStyles applies the first document's styles to all merged content, best when you want a uniform look. KeepDifferentStyles retains distinct styles and merges only identical ones. For branded reports with a fixed template, use UseDestinationStyles with the template as position 0.
DocContent must be file binary, not a URL or path
The DocContent field for each document expects the raw binary content of the Word file, not a SharePoint URL or file path. Use the Power Automate Get File Content action on each document first, then map its output body to DocContent. For SharePoint, Get File Content Using Path returns the binary directly, no additional encoding step needed.
Power Automate PDF4me Merge Documents action showing the Documents array with two entries: each containing Filename, DocContent mapped from a SharePoint Get File Content step, SortPosition 0 and 1, and FormatMode UseDestinationStyles: plus Merge Options Compliance Level set to Transitional

Build the Documents array with one entry per file. Map DocContent from a Get File Content step, not a URL. SortPosition 0 is the base document; all others append in order.

Parameters

Required: Documents array with at least one entry. Each entry requires Filename, DocContent (file binary), and SortPosition. FormatMode and Merge Options are optional.

ParameterRequiredWhat it doesExample
DocumentsYesArray of document objects to merge. Each object requires Filename, DocContent, and SortPosition. The array must contain at least one entry. Documents merge in ascending SortPosition order.[{Filename, DocContent, SortPosition}]
Documents[].FilenameYesFilename of the document including extension. Must be .docx or .doc. Used for format detection and document identification during merge.chapter1.docx
Documents[].DocContentYesRaw binary content of the Word file. Map from the output body of a SharePoint Get File Content or OneDrive Get File Content action. Do not pass a URL, path, or filename string here.File Content body
Documents[].SortPositionYesInteger determining merge order. The document with the lowest SortPosition becomes the base document. All others are appended in ascending order. Use any integers: 0, 1, 2 or 10, 20, 30 are both valid.0
Documents[].FormatModeNoHow styles are handled for this document during merge. Options: KeepSourceFormatting (default: preserves document's own styles), UseDestinationStyles (adopts base document styles), KeepDifferentStyles (retains distinct styles only).UseDestinationStyles
Merge Options Time ZoneNoTimezone identifier added to the merged document metadata. Use standard identifiers like UTC, Asia/Kolkata, or America/New_York. Default: none.UTC
Merge Options Compliance LevelNoOOXML compliance standard for the output document. Options: ECMA (ECMA-376 2006), Transitional (ISO 29500 Transitional, default and recommended), Strict (ISO 29500 Strict). Use Transitional for broadest Microsoft 365 compatibility.Transitional

Output Fields

FieldTypeWhat it contains
documentBinaryThe merged Word document as a binary. Map into SharePoint Create File, Send Email attachment, or a Convert Word to PDF action.
SuccessBooleantrue if the merge completed without errors. Use in a Condition step to branch on failure and send an error notification.
Error MessageStringHuman-readable error description if Success is false. Null when successful. Include in failure notification emails.
ErrorsArrayArray of detailed error objects when Success is false. Each entry has Code and Message fields for debugging.

Common Error Messages

Error MessageCauseFix
No documents to mergeDocuments array is null or emptyPass at least one document object in the Documents array with Filename, DocContent, and SortPosition.
Error loading document from bytesInvalid or corrupted Word file in DocContentVerify DocContent comes from a Get File Content action returning a valid .docx binary: not a URL or path.
Unknown FormatMode, defaulting to KeepSourceFormattingInvalid FormatMode valueUse only: KeepSourceFormatting, KeepDifferentStyles, or UseDestinationStyles.
Error merging documentsGeneral exception during mergeCheck that all documents are valid Word files (.docx). Review the Errors array for details.

Quick Setup

  1. In your Power Automate flow, click + Add an action and search for PDF4me Word.
  2. Select Merge Documents.
  3. Enter your PDF4me API key in the connection dialog (or select an existing connection).
  4. For each document to merge, add a SharePoint Get File Content or OneDrive Get File Content action above this step.
  5. In the Documents array, add one entry per file. Set Filename (with .docx), DocContent (binary from the Get File Content step), and SortPosition (0 for the base, 1, 2... for subsequent files).
  6. Set FormatMode: use UseDestinationStyles if the base document (position 0) is your branded template.
  7. Set Merge Options Compliance Level to Transitional for broadest compatibility.
  8. Wire the document output into a SharePoint Create File or Send Email action. Add a Condition on Success to handle failures with an error notification.

Workflow Examples

Workflow ExamplesCommon Power Automate flow patterns using Merge Documents.
Report sections approved → merge in order → email assembled report
  1. A SharePoint item change triggers the flow when all report sections are marked "Approved" in a status column.
  2. Four Get File Content steps retrieve the cover page (position 0), executive summary (1), main body (2), and appendices (3) from the Reports library.
  3. Merge Documents combines all four in SortPosition order with FormatMode set to UseDestinationStyles, the cover page template's styles apply uniformly throughout.
  4. A Condition on Success routes failures to a Teams notification for the report owner.
  5. Send an Email attaches the merged DOCX report to the management distribution list. SharePoint Create File archives it in the Published Reports library.
Contract sections finalized → merge → convert to PDF → route for execution
  1. An approval trigger fires in Power Automate when the legal review step is completed in the contract approval workflow.
  2. Get File Content steps retrieve the contract header (0), Terms & Conditions (1), specific clauses (2), and signature pages (3) from the Legal library.
  3. Merge Documents assembles the complete contract. FormatMode is KeepSourceFormatting and Compliance Level is Strict for legal document standards.
  4. A PDF4me Convert Word to PDF action generates a print-ready PDF of the merged contract.
  5. Send an Email delivers the numbered, final contract to counterparties. SharePoint archives both the DOCX and PDF in the Executed Contracts folder.
Variable number of proposal sections → loop → collect → merge → send to client
  1. A manual trigger fires when a proposal is ready. SharePoint Get Files retrieves all DOCX sections from the Proposal Sections folder for that deal.
  2. An Apply to Each loop iterates over the file list. Each iteration runs Get File Content and appends a document object (Filename, binary, iteration index as SortPosition) to an array variable.
  3. After the loop, Merge Documents receives the complete array. FormatMode is UseDestinationStyles, the first file in the folder (position 0) is always the branded cover template.
  4. The merged DOCX uploads to the Client Deliverables SharePoint library. Send an Email delivers it to the client contact with a personalized cover message.

Frequently Asked Questions

What is SortPosition and how do I control the merge order?+
SortPosition is an integer assigned to each document in the Documents array. The action merges documents in ascending order: position 0 becomes the base document and all others are appended in order. You can use any integers: 0, 1, 2 or 10, 20, 30 are equally valid. When processing files from an Apply to Each loop in Power Automate, use the loop iteration index as SortPosition to ensure a deterministic merge order regardless of how SharePoint returns the files.
Which FormatMode should I use for branded company documents?+
Use UseDestinationStyles when the document at SortPosition 0 is your branded template: all merged content from other documents adopts the template's styles for a uniform look throughout the assembled document. Use KeepSourceFormatting (the default) when each document should retain its own styles, appropriate for merging independently authored sections where style variety is acceptable. Use KeepDifferentStyles when you want to preserve distinct styles from different contributors while merging identical style definitions.
Why does DocContent need to be the file binary and not a URL or SharePoint path?+
The DocContent field expects the raw binary bytes that make up the DOCX file. Use a SharePoint Get File Content or OneDrive Get File Content action before this step and map its Body (or File Content) output into DocContent. Passing a URL, a SharePoint path string, or a filename causes an invalid document error because the action cannot download or resolve file references: it can only process binary content it receives directly.
How do I merge a variable number of files: for example, all DOCX files in a SharePoint folder?+
Use an Apply to Each loop. Add a SharePoint Get Files action to list all DOCX files in the folder. Inside the loop, add Get File Content and append a document object (Filename, binary Content, and current item index as SortPosition) to an array variable initialized before the loop. After the loop exits, pass the completed array variable to the Merge Documents action. This pattern handles any number of files: from 2 to 200, without changing the flow structure.
What does the action return and how do I handle merge failures gracefully?+
The action returns document (merged DOCX binary), Success (boolean), Error Message (string), and Errors (array). After the action, add a Condition step that checks if Success equals true. On the false branch, use Send an Email or Post a Message (Teams) to notify the flow owner with the Error Message value so failures are visible without having to check run history manually. On the true branch, proceed with the Create File and email distribution steps.

Get Help