red6 / pdfcompare

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

Getting page numbers as a result of comparison #91

Closed apathan123 closed 3 years ago

apathan123 commented 3 years ago

Is it possible to get the page numbers which have diffs as a rsult of comparison. I can see pdfComparator prints them in the log.

finsterwalder commented 3 years ago

You can use CompareResult.getDifferences() and extract the page numbers from there. Not perfect, but doable. Something along the lines of: getDifferences.stream().map(pageArea -> pageArea.getPage()).distinct().... Just typed that from the top of my head without testing it... ;-)

tpiekarski commented 3 years ago

What do you think providing a CLI parameter and/or a method for shortcut-ing at CompareResult, something like getInequalPages() which would return a list with all pages being different? Should you like this idea I could take a closer look into the code and prepare a PR in the next week.

apathan123 commented 3 years ago

IF we can get this the way you described @tpiekarski nothign like it! Basically am using the result and notifying in slack to the group that somehting has changed from last build. FOr larger pDFs its easy for them to just to gothat page and see whats differrent. For minor changes it takes lot of scrolling up and down to spot diff specially when they are numbers or small texts. The product is brilliant already but this kind of feature, I am sure will further enhance the usability.

apathan123 commented 3 years ago

You can use CompareResult.getDifferences() and extract the page numbers from there. Not perfect, but doable. Something along the lines of: getDifferences.stream().map(pageArea -> pageArea.getPage()).distinct().... Just typed that from the top of my head without testing it... ;-)

Let me try. Thanks for the guideline

finsterwalder commented 3 years ago

there is already a config switch to only keep unequal pages: addEqualPagesToResult=true Setting this to false will remove all equal pages from the result. Maybe that will solve your problem?

apathan123 commented 3 years ago

there is already a config switch to only keep unequal pages: addEqualPagesToResult=true Setting this to false will remove all equal pages from the result. Maybe that will solve your problem?

@finsterwalder When I try to set it through Simple Environment, it says method se.addEqualPagesToResult(true) is undefimced for Simple Environment. Can you help me set it thorugh program like other parameters: se.addEqualPagesToResult(true);

finsterwalder commented 3 years ago

The method name is: setAddEqualPagesToResult(final boolean b)

apathan123 commented 3 years ago

The method name is: setAddEqualPagesToResult(final boolean b) Same issue @finsterwalder . It also does nto show up in available methods for pdfcomaparotor. Am I missign something?

finsterwalder commented 3 years ago

I don't know what the problem may be. See: https://github.com/red6/pdfcompare/blob/6236dad8e0a3ab63913861e03a6e88712d3e7bf6/src/main/java/de/redsix/pdfcompare/env/SimpleEnvironment.java#L175 This code has been there since March 2020 without changes... :thinking:

finsterwalder commented 3 years ago

Are you using the current version 1.1.57?

apathan123 commented 3 years ago

That wa sthe issue @finsterwalder . Not sure how did I overlook that. I was using 1.1.45 . Apologies for the series of quesitons. But I will also be waiting for getting pagenumbers with diff back though I can work with this funciton till then. Thanks again!

finsterwalder commented 3 years ago

I just release version 1.1.58, which adds a method Collection getPagesWithDifferences() to CompareResult.

tpiekarski commented 3 years ago

@finsterwalder Now, that's a new level of ignorance. Is this your new way how you treat contributors? I know I am a contributor just passing by, but at least have the courtesy to answer me instead of ignoring me and implementing the feature yourself. I really expected more from you.

finsterwalder commented 3 years ago

I'm really Sorry, @tpiekarski. I didn't mean to offend you. I read over your comment, but since there were other comments under yours, which I respond to, I kinda forgot about your offer while passing along. Sorry for that. Then I noticed, while checking the code anyways, that it was just a few minutes change to add the method and I just did it. I didn't think much of it. Sorry.

PdfCompare already contains several contributions from other developers and I'm glad, that other people add features, that I don't have the time to do or that I don't prioritize high enough. SimpleEnvironement, the CLI and Exclusion Management in the UI are some of the contributed features.

apathan123 commented 3 years ago

That worked like charm! Thanks so much!