Skip to main content

Compare Documents - Document Comparison API

PDF4me Compare Documents enables you to compare two Word documents and track changes with comprehensive comparison options. This API service processes two Word files and generates a comparison document with detailed change tracking, customizable comparison settings, revision management, and professional comparison reports. The API receives both document contents through REST API calls, utilizing Base64 encoding for secure transmission. With full control over formatting, case sensitivity, comments, tables, fields, footnotes, textboxes, and headers/footers, this solution is ideal for document review, version control, and collaborative editing workflows.

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​

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​

  • Document Comparison: Compare two Word documents and identify all differences
  • Track Changes: Generate documents with tracked changes showing modifications
  • Customizable Options: Control what types of changes to track or ignore
  • Revision Management: Clean up existing revisions before comparison
  • Author Attribution: Assign changes to specific authors for accountability
  • Professional Output: Generate clean comparison documents with revision tracking
  • Multiple Format Support: Compare .docx and .doc files
  • Advanced Filtering: Ignore formatting, case changes, comments, tables, and more

REST API Endpoint​

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

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

REST API Parameters​

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

Important: Parameters marked with an asterisk (*) are required and must be provided for the API to function correctly.

ParameterRequiredWhat it doesExample
firstDocumentRequiredObject carrying this operation's settings. Its fields are the firstDocument rows below.{ "Name": "original.docx" }
firstDocument.NameRequiredFile name including its extension. Type: string.
firstDocContentRequiredThe original document, base64-encoded. Type: string.UEsDBBQABgAIAAAA...
secondDocumentRequiredObject carrying this operation's settings. Its fields are the secondDocument rows below.{ "Name": "modified.docx" }
secondDocument.NameRequiredFile name including its extension. Type: string.
secondDocContentRequiredThe changed document, base64-encoded. Type: string.UEsDBBQABgAIAAAA...
comparisonOptionsRequiredSend `{}` to use the defaults.{ "ignoreFormatting": false, "author": "John Doe" }
comparisonOptions.ignoreFormattingOptionalIgnore formatting changes. Type: boolean.
comparisonOptions.ignoreCaseChangesOptionalIgnore changes in upper/lower case. Type: boolean.
comparisonOptions.ignoreCommentsOptionalIgnore comments. Type: boolean.
comparisonOptions.ignoreTablesOptionalIgnore table changes. Type: boolean.
comparisonOptions.ignoreFieldsOptionalIgnore field changes. Type: boolean.
comparisonOptions.ignoreFootnotesOptionalIgnore footnotes. Type: boolean.
comparisonOptions.ignoreTextboxesOptionalIgnore text boxes. Type: boolean.
comparisonOptions.ignoreHeadersAndFootersOptionalIgnore headers and footers. Type: boolean.
comparisonOptions.authorOptionalAuthor name shown on the tracked changes. Type: string.
isAsyncOptionalProcess the request in the background. The call returns `202 Accepted`; poll the `Location` URL (`GetActionStatus`) for the result. Type: boolean.

Comparison Options​

The API provides fine-grained control over what changes to track:

Content Options:​

  • ignoreFormatting: Focus on text content, ignore styling changes
  • ignoreCaseChanges: Case-insensitive comparison
  • ignoreComments: Exclude comment changes from comparison
  • ignoreTables: Exclude table structure and content changes
  • ignoreFields: Exclude field updates (auto-updating content)

Document Element Options:​

  • ignoreFootnotes: Exclude footnote changes
  • ignoreTextboxes: Exclude textbox changes
  • ignoreHeadersAndFooters: Exclude header/footer changes

Attribution:​

  • author: Set the author name for tracked changes in the comparison document

Output​

The PDF4me Compare 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": "comparison-result.docx",
"success": true,
"errorMessage": null
}

Response Fields:

  • document (string): The Word document with tracked changes showing all differences, encoded as Base64 string
  • fileName (string): The output Word file name with comparison results
  • 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. Open the document in Word to review tracked changes
  4. Accept or reject changes 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 - document contains tracked changes

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 (Required Fields Only):

{
"firstDocument": { "Name": "original.docx" },
"firstDocContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"secondDocument": { "Name": "modified.docx" },
"secondDocContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC..."
}

Advanced Example (With Comparison Options):

{
"firstDocument": { "Name": "original.docx" },
"firstDocContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"secondDocument": { "Name": "modified.docx" },
"secondDocContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"comparisonOptions": {
"ignoreFormatting": false,
"ignoreCaseChanges": false,
"ignoreComments": true,
"ignoreTables": false,
"ignoreFields": true,
"ignoreFootnotes": false,
"ignoreTextboxes": false,
"ignoreHeadersAndFooters": false,
"author": "Legal Review System"
}
}

Content-Only Comparison Example:

{
"firstDocument": { "Name": "original.docx" },
"firstDocContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"secondDocument": { "Name": "modified.docx" },
"secondDocContent": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC...",
"comparisonOptions": {
"ignoreFormatting": true,
"ignoreCaseChanges": true,
"ignoreComments": true,
"ignoreFields": true,
"author": "Content Review"
}
}

Code Samples​

The PDF4me Compare 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 comparing Word documents:

Industry Use Cases & Applications​

Legal & Professional Services Use Cases

  • Contract Review: Compare contract versions to identify changes and modifications
  • Legal Document Updates: Track changes in legal briefs, agreements, and court documents
  • Compliance Monitoring: Compare policy documents to ensure regulatory compliance
  • Client Document Review: Track changes in client-facing legal documents

Get Help​