red6 / pdfcompare

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

Can we get difference output in JSON format instead of PDF? #61

Closed jyteshpunjwani closed 4 years ago

jyteshpunjwani commented 4 years ago

Hey, i was wondering if we can get difference output in json instead of pdf so i can just grab the difference area from JSON output?

finsterwalder commented 4 years ago

What exactly do you expect? What would be in the JSON? How would it look like? Could you give an example?

finsterwalder commented 4 years ago

@jyteshpunjwani Could you please respond to my question? Otherwise I can't really do anything.

rmcdouga commented 4 years ago

I don't know about the original poster however I would like to see the differences written out in the exclusion JSON format so that it would be possible to just use the files as a starting point for an exclusion on the next run.

finsterwalder commented 4 years ago

The CompareResult has a Method: getDifferences(), that gives you a Collection. This is what you want, just not in JSON format. You can serialize it to JSON with Jackson like this:

ObjectMapper objectMapper = new ObjectMapper(); String exclusionJson = "exclusions: " + objectMapper.writeValueAsString(compareResult.getDifferences());

Would that be enough?

finsterwalder commented 4 years ago

I could add that as a method to CompareResultImpl, but I'm a little unsure, since pulling in Jackson might cause problems with other projects that already use a different version of Jackson etc. And just for this simple feature, I'm not sure I want to pull that in.

finsterwalder commented 4 years ago

I created a simple CompareResult.getDifferencesJson()-method. It is included in release 1.1.47, which should land in maven central in a few hours...

rmcdouga commented 4 years ago

That all makes sense (including not introducing Jackson). Thanks for looking at this...