Skip to main content

Comparing documents

Open a document and compare it with a revised version as soon as the editor loads. The editor opens in view mode, and the comparison starts on its own, without the user clicking Compare in the editor.

info

The editor opens the original file and, as soon as it is ready, compares it with the revised file. The differences appear as tracked changes.

original.docxvsrevised.docxLoading…

How it works​

  1. The editor opens the original file in view mode:

    const config = {
    document: {
    fileType: "docx",
    key: "original-key",
    title: "original.docx",
    url: "https://example.com/original.docx",
    },
    documentType: "word",
    editorConfig: {
    mode: "view",
    },
    };
  2. When the editor fires the onDocumentReady event, the setRequestedDocument method is called with the compare type and the URL of the revised file:

    config.events = {
    onDocumentReady() {
    docEditor.setRequestedDocument({
    c: "compare",
    fileType: "docx",
    url: "https://example.com/revised.docx",
    token: "<token>",
    });
    },
    };

    const docEditor = new DocsAPI.DocEditor("placeholder", config);

    If JWT is enabled on the document server, sign the object passed to setRequestedDocument with the same secret as the editor config. See Signature for details.

tip

To compare documents on the server without opening an editor, use the CompareDocuments method in Document Builder. The method requires a file opened with builderJS.OpenTmpFile, which is available only in Document Builder.