Skip to main content

Merge Documents - Document Assembly API

PDF4me Merge Documents enables you to combine multiple Word documents into a single document with advanced formatting and compliance options. This API service processes multiple Word files and merges them with flexible document ordering, customizable formatting modes, compliance level settings, timezone metadata, and intelligent style handling. The API receives document contents through REST API calls, utilizing Base64 encoding for secure transmission. With support for unlimited document merging and full control over merge behavior, this solution is ideal for document assembly, report consolidation, and content management workflows.

Authenticating Your API Request

To access the PDF4me REST API, every request must include proper authentication credentials. Authentication ensures secure communication and validates your identity as an authorized user of the REST API.

Key Features

  • Multiple Document Support: Merge unlimited number of documents into one
  • Simple Array Structure: Easy-to-use array of Base64-encoded document contents
  • Ordered Merging: Documents merged in the order they appear in the array
  • Base Document Concept: First document becomes the foundation for merging
  • Multiple Format Support: Merge Word documents, PDFs, and other supported formats

REST API Endpoint

The PDF4me REST API uses standard HTTP methods to interact with resources. All document merging operations are performed through a single endpoint:

  • Method: POST
  • Endpoint: office/ApiV2Word/MergeDocuments

REST API Parameters

Complete list of parameters for the Merge Documents REST API. Parameters are organized by category for better understanding and implementation.

Important: Parameters marked with an asterisk (*) are required. The documents array must contain at least one document.

Required Parameters

ParameterTypeDescriptionExample
documents*ArrayArray of document objects to be merged. Must contain at least one document. Each object must have filename (string) and docContent (Base64 string). Documents are merged in the order they appear in the array. Optional per-document fields: sortPosition (integer), formatMode (string)[{ "filename": "doc1.docx", "docContent": "base64..." }, { "filename": "doc2.docx", "docContent": "base64..." }]

Optional Parameters

ParameterTypeDescriptionExample
mergeOptionsObjectMerge options (formatting, compliance, etc.). See plugin model for available properties{}

Document Merge Order

Documents are merged in the order they appear in the documents array:

  • First document in the array becomes the base document
  • All subsequent documents are appended to the base document in array order

Output

The PDF4me Merge Documents REST API returns different responses based on the processing mode. The API returns the Word document as a Base64-encoded string in JSON format, not as binary data.

Synchronous Processing (Default)

The API processes the request and returns:

Status Code: 200 OK

Content-Type: application/json

Response Body:

{
"document": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"fileName": "merged-document.docx",
"success": true,
"errorMessage": null
}

Response Fields:

  • document (string): The merged Word document containing all input documents, encoded as Base64 string
  • fileName (string): The output Word file name
  • success (boolean): Indicates whether the request succeeded
  • errorMessage (string or null): Error details when success is false

How to Use:

  1. Extract the document field from the JSON response (Base64)
  2. Decode the Base64 string to get the binary Word document data
  3. Save or process the Word file as needed

Example (JavaScript):

const response = await fetch(url, options);
const data = await response.json();
const wordBytes = atob(data.document); // Decode Base64
// Save or process wordBytes

Request Example

Content-Type: application/json
Authorization: Basic YOUR_BASE64_ENCODED_API_KEY

Note:

  • Get your API key from the PDF4me Dashboard
  • The API key must be Base64 encoded and prefixed with "Basic " in the Authorization header
  • Example: If your API key is abc123, encode it to Base64 and use Authorization: Basic YWJjMTIz

Payload

Basic Example (Two Documents):

{
"documents": [
{ "filename": "doc1.docx", "docContent": "base64EncodedDocument1" },
{ "filename": "doc2.docx", "docContent": "base64EncodedDocument2" }
]
}

Advanced Example (Multiple Documents with Merge Options):

{
"documents": [
{ "filename": "doc1.docx", "docContent": "base64EncodedDocument1" },
{ "filename": "doc2.docx", "docContent": "base64EncodedDocument2" },
{ "filename": "doc3.docx", "docContent": "base64EncodedDocument3" }
],
"mergeOptions": {}
}

Code Samples

The PDF4me Merge Documents REST API provides code samples in multiple programming languages. Choose the language that best fits your development environment:

C# (CSharp) Sample

Complete C# implementation for merging Word documents:

Industry Use Cases & Applications

Legal & Professional Services Use Cases

  • Contract Assembly: Combine contract sections into complete legal documents
  • Legal Brief Consolidation: Merge multiple brief sections into comprehensive legal briefs
  • Compliance Documentation: Consolidate compliance documents for regulatory submissions
  • Client Document Assembly: Combine client-specific documents into complete packages

Get Help