vinsguru / pdf-util

PDF Compare Utility
98 stars 69 forks source link

Comparison stops as soon as differences are found #5

Closed florianbepunkt closed 6 years ago

florianbepunkt commented 7 years ago

Use case: I have a couple of pdfs with slight differences on multiple pages. I want to use the tool to highlight the differences.

Exspected outcome: Multiple png files with the highlighted differences

Actual outcome: I only get the first page with the highlighted differences

Is this intended behaviour or am I missing something

import com.testautomationguru.utility.PDFUtil;
import com.testautomationguru.utility.CompareMode;

public class PDFCompare {
  public static void main(String[] args) throws java.io.IOException{
    PDFUtil pdfUtil = new PDFUtil();

    String file1="files/doc1.pdf";
    String file2="files/doc2.pdf";

    pdfUtil.setCompareMode(CompareMode.VISUAL_MODE);

    //if you need to store the result
    pdfUtil.highlightPdfDifference(true);
    pdfUtil.setImageDestinationPath("files/");
    pdfUtil.compare(file1, file2, 2, 5);
  }//End of main
}

Compile & executing

javac -cp '.:pdfutil.jar' PDFCompare.java
java -cp '.:pdfutil.jar' PDFCompare
vinsguru commented 7 years ago

Yes, That is a default behavior. It exits as soon as a mismtach is found.

To compare all pages, use something like this

pdfutil.compareAllPages(true);
florianbepunkt commented 7 years ago

@vinsguru thank you! would it also be possible to compare multiple pdfs? for example compare three documents?

vinsguru commented 6 years ago

@florianbepunkt No. You can do that yourself - simply as shown here.

List<String> pdfsList = Arrays.asList("a.pdf", "b.pdf", "c.pdf", "d.pdf");

compareAll(pdfsList);

public boolean compareAll(List<String> pdfsList){
    for(int i=0; i < pdfsList.size() - 1; i++){
        if(!pdfUtil.compare(pdfsList.get(i), pdfsList.get(i+1))){
            return false;
        }
    }
    return true;
}