red6 / pdfcompare

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

command line app #51

Closed eev2 closed 4 years ago

eev2 commented 5 years ago

Hi. Could you please provide instructions on how to compile this into a command line application for comparing two pdfs? Thanks.

finsterwalder commented 5 years ago

I didn't yet programm anything, that would allow to run this as a command line application. This would require to programm a new class, that handles command line arguments and calls a compare. That's a new feature request, which makes total sense...

tpiekarski commented 5 years ago

When work for this issue did not start yet, I'd like to offer a PR. Starting with two command line arguments: one for the actual image and a second one for the expected image.

But what output did you expect when there are differences? Would a zero (no difference) or non zero (difference) return code be enough - the differences would be logged like now with the UI anyway? Or do you need the coordinates of differences in some other way, like CSV?

finsterwalder commented 5 years ago

Great that you are offering some help! Some basics first: I would use apache commons CLI (or is there something better?) to process command line arguments. (https://commons.apache.org/proper/commons-cli/)

Two parameters is probably not quite enough. You have expected, actual and usually the result-file. Maybe we use two parameters as given: expected and actual. More with switches. Say -o and --output-file for the output filename. Then we can add further parameters later, like another optional filename, where differences found will be written to.

The return code should be 0 for equal documents and 1 for not equal. If differences are only found in ignored areas, than 0 should be returned as well.

That's probably enough for now.

tpiekarski commented 5 years ago

Sounds reasonable, so we would get the following CLI pdfcompare \<expected> \<actual> -o|--output-file=result.pdf (and later probably something like -d|--differences=differences.log)

There are possible alternatives to Apache Commons CLI, like PicoCLI and JCommander . Both are annotation driven and at the first look they seem to be easier to handle. Did you consider these already?

edit: The arguments for \<expected> \<actual> haven't been rendered correctly.

finsterwalder commented 5 years ago

I don't know the other libs. I worked with Apache Commons CLI before, that's why I mentioned it. If you find one of the other is a better choice, go for it.

bartisimos commented 5 years ago

May I offer here my outcome of some christmas holiday exercises ? used this parameters: Call 2: "fileblue:files\blue\Dok1.pdf" "filecreate:files\Create\Dok2.pdf" "fileresult:files\results\Dokcompare" "fileignore:files\ignore\test.conf" "percentage:0" with a new class.

Short definition of words: blue = blueprint - as it should be, create = to be compared document, result is the path to add the outcome, ignore file the name of the file with ignore information, percentage out of the config file - ...

If you are interested, happy to share. But I made a new project out of it - as described above - own class, own functions, etc.

finsterwalder commented 5 years ago

I don't like the very unusual syntax with colons. Besides the unusual wording, that is not self explanatory. Which library did you use to build it?

tpiekarski commented 5 years ago

I agree with @finsterwalder the CLI syntax you proposing @bartisimos is unusual.

What could be the benefits of this syntax at the command prompt? If we would run a web service accepting JSON payloads I'd be with you to some degree. To be frank at the command prompt I do not see any benefits at this moment.

However I'll start with the CLI like we talked about earlier and prototype a PR for review and discussion.

finsterwalder commented 4 years ago

A simple CLI is implemented.