red6 / pdfcompare

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

application.conf file location #80

Closed steevi2307 closed 4 years ago

steevi2307 commented 4 years ago

Hi,

It's been a long time that i not use java but I succeeded to use the pdfcompare tool inside eclipse IDE an make a jar file that can be used from my .NET application.

But I don't understand how to use the application.conf file to allowed difference in percent ... I tried to put this file in most of all directory but it doesn't seems to work.

Can you tell me what's wrong ? Pdfs are attached

2020-08-18_084714

New (P1).pdf Old (P1).pdf

Thanks :)

finsterwalder commented 4 years ago

application.conf needs to be on the Java classpath. Here this probably means, that it needs to be in src/main/resources. When you create a jar, you can either include the application.conf file, which makes it easy to access, but hard to change. Or you need to make sure, when you start the jar, that your application.conf file is in a location, that is part of the classpath.

finsterwalder commented 4 years ago

Alternatively you could also set the config programmatically. Have a look at IntegrationTest.whenMorePixelsAreDifferentThanAllowedDiffInPercentResultIsNotEqual() for an example.

finsterwalder commented 4 years ago

And another way: You can also use a system environment variable to do the configuration.

steevi2307 commented 4 years ago

Ok, it seems to work for the first page with that code (No differences are found)

final CompareResult result = new PdfComparator(x, y).withEnvironment(new SimpleEnvironment().setAllowedDiffInPercent(5)).compare(); if (result.isNotEqual()) { System.out.println("Differences are found"); result.writeTo(z); System.exit(1); }

But, if I take the entire document, it told me correctly that both documents are not equal but the resultfile show all differences ... is there a way to only show differences that are less than 5% of pixel difference ?

image

Thanks

finsterwalder commented 4 years ago

Currently there is not. You always get all the differences.

steevi2307 commented 4 years ago

Do you think it will be possible in a near future as an improvement ?

finsterwalder commented 4 years ago

There is a setting: addEqualPagesToResult When you set that to false, pages that are equal (or where the difference is below the allowed percentage) are not added to the result. Is that what you want?

steevi2307 commented 4 years ago

Actually, it's working very well but the best for me would be to have all pages with :

Do you think it's possible ?

Thanks ;)

finsterwalder commented 4 years ago

Possible is everything. It's Software after all. ;-) But not everything makes sense...

Including the pages from the expected or actual PDF file unchanged, even though they have differences, does not make sense to me. That would be confusing and would go against the basic concept of PdfCompare, IMHO. The only thing that would make sense to me is: Mark those pages somehow differently. Similar to ignored areas, that get a yellow background. So you can still see that there are differences, but you also immediately see, that they have been ignored.

But doing that is not trivial. You only know at the end, whether the number of differing pixels is above or below the threshold of allowedDiffInPercent. But the margins are drawn during the rendering. :-/

steevi2307 commented 4 years ago

OK, I will see what's the best later ;) Thanks for your advices

finsterwalder commented 4 years ago

I updated the README to more clearly describe the possibilities to specify a config file