Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

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 oldDocument = await instance.Core.createDocument(documentAFile); // Old file.
const newDocument = await instance.Core.createDocument(documentBFile); // New file.

// Compare the content of the documents.
const result = await oldDocument.compareContent(newDocument, {
  compareText: true,
  compareImages: true,
  colors: {
    replace: '#93B9FD',
    insert: '#C0FFEC',
    delete: '#FBBDBF'
  }
});

// Get an array containing document blob object of the comparison result.
const res = await Promise.all([result.base, result.other, result.merged].map(async (doc) => new Blob([await doc.getFileData()], { type: 'application/pdf' })));