Skip to content
ComPDF
DemoSampleAPI ReferenceFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Content Comparison

The steps to perform a content comparison are as follows:

  1. Open the two documents being compared.

  2. Create the CPDFCompare object.

  3. Set the colour and other properties of the comparison.

  4. Call compare.doCompare() to get the comparison results and save them to the document using the generateNewDoc() method.

This example shows how to add an content comparison:

Java
CPDFDocument baseDocument = new CPDFDocument();
baseDocument.open(rootDir + "/TestFiles/comparefile.pdf");
CPDFDocument comDocument = new CPDFDocument();
comDocument.open(rootDir + "/TestFiles/comparefile1.pdf");
printDividingLine();

CPDFCompare compare = baseDocument.createCompare(baseDocument, comDocument);
compare.setReplaceResColor(Color.decode("#93B9FD").getRGB());
compare.setInsertResColor(Color.decode("#C0FFEC").getRGB());
CPDFCompareResults result = compare.doCompare(0, 0, CPDFCompare.CompType.COMPAREALL.id, true);
compare.generateNewDoc(rootDir + "/out/compareTest.pdf");