使用 GroupDocs.Comparison 進行高效的文檔比較。

概述

在當今快速變化的數位世界中,文件協作和比較對於效率和生產力至關重要。 GroupDocs.Comparison for Node.js 使開發人員能夠輕鬆地將強大的文件比較功能集成到他們的應用程序中。本指南將引導您完成安裝、功能和代碼示例。

GroupDocs.Comparison for Node.js 是什麼?

GroupDocs.Comparison for Node.js 是一個強大的庫,專為希望構建能夠比較文檔文件的應用程序的開發人員設計。它支持多種文檔格式,幫助用戶輕鬆識別版本之間的變更,並確保文檔的完整性。

下載 GroupDocs.Comparison for Node.js

按照以下步驟下載並開始使用 GroupDocs.Comparison for Node.js:

  1. 訪問官方 GroupDocs Releases page
  2. 找到 GroupDocs.Comparison for Node.js 套件。
  3. 下載最新版本。
  4. 解壓縮該套件並在終端中導航到該目錄。

您也可以使用 NPM 安裝 GroupDocs.Comparison for Node.js:

npm i @groupdocs/groupdocs.comparison

下載後,您可以運行以下示例代碼片段來驗證安裝:

const { Comparer } = require('@groupdocs/groupdocs.comparison');

// Load the source document
const comparer = new Comparer("source.docx");

// Specify the second file for comparison
comparer.add("target.docx");

// Save comparison result to a specified file
comparer.compare("result.docx");

範例來源和目標文件:

Sample source and target files for GroupDocs.Comparison.

樣本結果檔案:

比較後的結果檔案。

主要特徵概覽

  • 多種格式支持:比較各種文檔格式,包括 Word、PDF 和 Excel。
  • 視覺比較:生成文件中的視覺差異,以提供對變更的清晰見解。
  • 自動比較:自動比較文件,無需手動干預。
  • 靈活性:輕鬆整合到您的現有 Node.js 應用程式中,幾乎不需要任何配置。
  • 詳細報告生成:生成全面的比較報告,總結檢測到的變化。

常見使用案例

以下是一些可以有效使用 GroupDocs.Comparison 的實際場景:

比較兩個 Word 文檔

要比較兩個 Word 文件並突出顯示差異,請按照以下步驟操作:

  1. 初始化比較器。
  2. 加載文檔。
  3. 添加比較選項(可選)。
  4. 執行比較。

這裡有一段代碼片段來演示這個用例:

const { Comparer, CompareOptions, StyleSettings } = require('@groupdocs/groupdocs.comparison');
const java = require('java');
const Color = java.import('java.awt.Color');

async function compareWordDocuments() {
    // Initialize the comparer object with the source file path
    const comparer = new Comparer("source.docx");

    // Add the target file for comparison
    comparer.add("target.docx");

    const compareOptions = new CompareOptions();
    const styleSettings = new StyleSettings();
    styleSettings.setUnderline(true); // Set font underline
    styleSettings.setFontColor(Color.GREEN); // Set font color as green
    styleSettings.setHighlightColor(Color.RED);  // Set highlight color as red
    compareOptions.setInsertedItemStyle(styleSettings); // Set style settings for inserted items

    // Perform the compare operation
    await comparer.compare("result.docx", compareOptions);
}

compareWordDocuments();

比較 PDF 文件

您也可以以類似的方式比較 PDF 文件。這裡有一個基本範例:

  1. 請指定 PDF 檔案的路徑。
  2. 添加比較選項(可選)。
  3. 執行比較。
const { Comparer, CompareOptions, StyleSettings } = require('@groupdocs/groupdocs.comparison');
const java = require('java');
const Color = java.import('java.awt.Color');

async function comparePdfDocuments() {
    // Initialize the comparer object with the source file path
    const comparer = new Comparer("source.pdf");

    // Add the target file path to the comparer object
    comparer.add("target.pdf");

    // Configure comparison options
    const compareOptions = new CompareOptions();
    const styleSettings = new StyleSettings();
    styleSettings.setUnderline(true); // Set font underline
    styleSettings.setFontColor(Color.BLUE); // Set font color as blue
    compareOptions.setInsertedItemStyle(styleSettings); // Set style settings for inserted items

    // Perform the compare operation
    await comparer.compare("result.pdf", compareOptions);
}

comparePdfDocuments();

透過遵循這些片段,您可以在您的 Node.js 應用程序中設置強大的文件比較功能。

另請參見

下載免費試用版

您可以從 releases page 下載 GroupDocs.Comparison 的免費試用版。此外,若要在不受限制的情況下測試該庫,請考慮在 GroupDocs Temporary License 獲取臨時許可證。

With GroupDocs.Comparison for Node.js, integrating advanced document comparison capabilities into your applications has never been easier. Start enhancing your document processing workflow today!