Skip to content
Guides

Content Comparison

Content comparison is often used to quickly find the changes between different PDF versions, and is suitable for files with much text information. The content that can be compared includes text, images, etc.

javascript
// Get the file stream of the compared files.
const documentA = await fetch('https://example.com/documentA.pdf');
const documentABlob = await documentA.blob();
const documentAFile = new File([documentABlob], 'documentA.pdf');
const documentB = await fetch('https://example.com/documentB.pdf');
const documentBBlob = await documentB.blob();
const documentBFile = new File([documentBBlob], 'documentB.pdf');

const data = {
  leftFile: documentAFile, // Old file.
  rightFile: documentBFile, // New file.
  type: 1, // The type of document comparison.
  textCompare: true,
  imgCompare: true,
  replaceColor: '#93B9FD',
  insertColor: '#C0FFEC',
  deleteColor: '#FBBDBF'
};

// Get an array containing document blob object of the comparison result.
const res = await docViewer.compare(data);