Compare of Variables and Document properties

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

On this page

GroupDocs.Comparison allows you to compare various properties of a Word document such as Variable, Built, and Custom properties.

Use the following methods of the CompareOptions class to enable comparison functions for document properties:

  • setCompareVariableProperty() allows the comparison of variable properties
  • setCompareDocumentProperty() allows the comparison of built and custom properties

The following code snippet shows how to activate the comparison of the variable, built and custom properties:

'use strict';

// Import the GroupDocs Comparison Node.js SDK
const groupdocs = require('@groupdocs/groupdocs.comparison');

 // Enable strict mode for better error handling
 // Define file paths for source, target, and output documents
const sourcePath = 'sample-files/source.docx';
const targetPath = 'sample-files/target.docx';
const outputPath = 'result.docx';

 // Initialize the comparer with the source document
const comparer = new groupdocs.Comparer(sourcePath);

 // Add the target document to be compared against the source
comparer.add(targetPath);

 // Create a CompareOptions instance to customize comparison settings
const options = new groupdocs.CompareOptions();

 // Enable comparison of variable (custom) properties
options.setCompareVariableProperty(true);

 // Enable comparison of built-in document properties
options.setCompareDocumentProperty(true);

 // Execute the comparison and save the result to the output path
comparer.compare(outputPath, options);

// Terminate the process with a success exit code
process.exit(0);

This example creates a Comparer instance with the source document, adds the target document, and creates a CompareOptions object. It enables comparison of both variable properties (using setCompareVariableProperty(true)) and document properties including built-in and custom properties (using setCompareDocumentProperty(true)), then performs the comparison with these options. Any differences in document properties will be highlighted in the result document.

The result is as follows:

On this page