red6 / pdfcompare

A simple Java library to compare two PDF files
Apache License 2.0
220 stars 66 forks source link

WARN de.redsix.pdfcompare.PdfComparator - No files found to compare. Tried Expected #95

Closed sankalprao closed 3 years ago

sankalprao commented 3 years ago

Hi,

I'm getting the following message "WARN de.redsix.pdfcompare.PdfComparator - No files found to compare Tried Expected" even the PDF files were present in the path specified. Please make the call to writeTo method when trying to reproduce the issue. A similar issue (https://github.com/red6/pdfcompare/issues/36) report was closed with the comments unable to reproduce.

*Following is my piece of code to compare two sample PDF's:

` package com.cucumbercraft.framework.pdfcomparison;

import de.redsix.pdfcompare.CompareResult; import de.redsix.pdfcompare.PdfComparator;

import java.io.IOException;

public class PdfCompare { public static void main(String[] args) throws IOException {

    final CompareResult result = new PdfComparator("Downloads\\Original.pdf", "Downloads\\Altered.pdf").compare();
    new PdfComparator("Downloads\\Original.pdf", Downloads\\Altered.pdf").compare().writeTo("Downloads\\diffOutput.pdf");
    if (result.isNotEqual()) {
        System.out.println("Differences found!");
    }
    if (result.isEqual()) {
        System.out.println("No Differences found!");
    }
    if (result.hasDifferenceInExclusion()) {
        System.out.println("Differences in excluded areas found!");
    }
    result.getDifferences(); // returns page areas, where differences were found        
}

}``

Following is the dependencies added to POM.xml

de.redsix pdfcompare 1.1.58

rweisleder commented 3 years ago

Hmm, I can still reproduce the warning only when both files are really not present. 🤔

Does your code run on Windows or Linux? Because under Linux "Downloads\\Original.pdf" does not denote the file Original.pdf in folder Downloads. Have you tried "Downloads/Original.pdf"? It should work on both platforms.

Internally the given paths are accessed with Files.newInputStream(Paths.get(...)) What happens if you put these on the beginning of your main method?

try (InputStream is1 = Files.newInputStream(Paths.get("Downloads\\Original.pdf"))) {
    try (InputStream is2 = Files.newInputStream(Paths.get("Downloads\\Altered.pdf"))) {
        System.out.println("both files exist");
    }
}
finsterwalder commented 3 years ago

Please try: Files.exists(Paths.get("your file here")). If this gives your false, then your file is not found. Also make sure your relative file path actually resolves to what you expect. Are you sure you start off in the "right" location? You could also try Paths.get("your file here").toAbsolutePath().toString() to find out, what Java resolves as a file.

sankalprao commented 3 years ago

Hi @rweisleder @finsterwalder ,

I was trying to pass the path of file as "Downloads\\Filename.pdf" and getting the error. I was able to successfully compare files when i passed the path of file as "C:\\Users\\sankalp.rao\\Downloads\\Filename.pdf". My apologies. I think as your rightly said, it was not able to find the file and thus that error.

I have closed this issue now. Thanks for your response. Appreciate it.

Cheers, Sankalp Rao

finsterwalder commented 3 years ago

You're welcome!