Page 1 of 2

Unable to do PDF comparison

Posted: 2018-12-14T01:15:43-07:00
by NukaCola
Hi all,

I want to compare 2 PDF files and a Google search revealed an older topic that explains how to do a PDF comparison using ImageMagick:
https://www.imagemagick.org/discourse-s ... hp?t=29277

Probably I'm missing something because when I run the suggested command line (on Windows 10 using ImageMagick-7.0.8-16-Q16-x64) it just gives me an error:
C:\Users\me>convert d:\Temp\A.pdf null: d:\Temp\B.pdf -compose Difference -layers composite -format %[fx:mean]\n info:
Invalid Parameter - null:
Any help is greatly appreciated!

Re: Unable to do PDF comparison

Posted: 2018-12-14T02:09:59-07:00
by snibgo
NukaCola wrote:Invalid Parameter
This is a message from a Microsoft program convert.exe, not ImageMagick.

For V7, I suggest you use "magick", not "convert" or "magick convert".

Re: Unable to do PDF comparison

Posted: 2018-12-14T02:48:15-07:00
by NukaCola
Thanks snibgo! This seems to work, at least.... for a start. :) After some minutes another error is reported:
convert: missing Null Image List Separator layers Composite @ error/mogrify.c/MogrifyImageList/8473.
As an additional information, the PDFs weigh ~66MB and ~18MB and contain 80 pages each.

Re: Unable to do PDF comparison

Posted: 2018-12-14T03:29:43-07:00
by snibgo
NukaCola wrote:convert: missing Null Image List Separator
Why are you still running "convert"?

What is your exact command?

Re: Unable to do PDF comparison

Posted: 2018-12-14T03:46:57-07:00
by NukaCola
Damn, I completely missed the "magic convert" part! :shock: I'm really sorry for that!

I corrected the command line but it's still giving me an error:
C:\Users\me>magick d:\Temp\A.pdf d:\Temp\B.pdf -compose Difference -layers composite -format %[fx:mean]\n info:
magick: missing Null Image List Separator layers Composite @ error/operation.c/CLIListOperatorImages/4297.

Re: Unable to do PDF comparison

Posted: 2018-12-14T03:56:25-07:00
by snibgo
NukaCola wrote:convert: missing Null Image List Separator
It is telling you there is no Null: in your image list. Compare your latest command to your original command. Why did you remove "Null:"?

Re: Unable to do PDF comparison

Posted: 2018-12-16T23:24:29-07:00
by NukaCola
Thanks again, snibgo! Now it's running just fine! I assume that the resulting numbers have to be interpreted as similarity? So 0.0 means 100% similarity while 0.01 means 99% similarity?!

Re: Unable to do PDF comparison

Posted: 2018-12-16T23:54:35-07:00
by NukaCola
Is there a way to generate difference images? So that just the differences are visible after the comparison?

Re: Unable to do PDF comparison

Posted: 2018-12-17T00:02:39-07:00
by fmw42
Perhaps you want:

magick imageA.pdf null: imageB.pdf -compose difference -layers composite diff_%d.png

You will get one png for each corresponding page of the pdf files. The brighter the result the more difference. You can even color code the results using a color LUT image with -clut.

See
https://imagemagick.org/Usage/compare/#difference

Re: Unable to do PDF comparison

Posted: 2018-12-17T04:57:11-07:00
by NukaCola
Awesome, this works like a dream and is exactly what I needed.

Thank you both and have a great Christmas time!

Re: [SOLVED] Unable to do PDF comparison

Posted: 2018-12-17T05:37:58-07:00
by snibgo
NukaCola wrote:I assume that the resulting numbers have to be interpreted as similarity? So 0.0 means 100% similarity while 0.01 means 99% similarity?!
Yes. %[fx:mean] is a number typically from 0.0 to 1.0. 0.0 means the images are identical. 1.0 means they are totally different (eg one is red and the other is cyan).

The mean difference can be greater than 1.0 when using HDRI and input pixel values are outside the range 0 to 100%.

Re: [SOLVED] Unable to do PDF comparison

Posted: 2019-03-20T04:44:00-07:00
by NukaCola
Sorry for bumping my old question, but I seem to be unable to format the difference images. At the moment the difference images are white and in my case the differences are just tiny so it's quite hard to find them on the screen. I got the hope that inversed colours will make it easier to spot the difference, so basically I would like to get black background and white differences, just like shown in https://imagemagick.org/Usage/compare/#difference.

But my command is giving me an error. I know I did something wrong so no need to say that :) but I can't figure out what the problem is.

My command:

Code: Select all

C:\Users\me\Desktop\Merge-Test>magick 1_Fonttest_Merge_L.pdf null: 2_Fonttest_Merge_R.pdf -compose difference -layers composite -highlight-color White -lowlight-color Black diff_%d.png
The error I get:
magick: unrecognized option `-highlight-color' at CLI arg 8 @ fatal/magick-cli.c/ProcessCommandOptions/428.

Re: [SOLVED] Unable to do PDF comparison

Posted: 2019-03-20T05:22:46-07:00
by NukaCola
Hmm it seems as if I am getting white background images only if the images are identical!? In case of a difference the images are dark red on black but... still can't seem to find the difference if it's just a minor one. Any suggestion on how to make even tiny difference visible would be awesome!

Re: Unable to do PDF comparison

Posted: 2019-03-20T06:13:11-07:00
by snibgo
"-highlight-color" is available when you are using "magick compare". When you are not using "magick compare", there is no concept of a highlight color, and the option is not available.

Fred showed you how to compare two PDF documents with the same number of pages, using a "null:" and "-compose difference -layers composite". Each output is black where there is no difference, and lighter means there is some difference.
NukaCola wrote:Hmm it seems as if I am getting white background images only if the images are identical!?
With what commands, and what input PDF files? If the inputs are CMYK, I suggest you convert them to sRGB.

Re: Unable to do PDF comparison

Posted: 2019-03-20T07:33:58-07:00
by NukaCola
I have no idea what that "null:" is basically used for? Anyway, yes the differences images are black, but the differences are hard to spot since they are so small and marked with dark red. For big pages, this is could be a real challenge to spot the difference. That's why I wanted to change the highlight colour.

The command that gave me an image that is all white (probably) was the one I posted before:
https://www.imagemagick.org/discourse-s ... 76#p164374

Note that it was just the first image of the whole series of images that was white.

The other idea I had was to simply export the PDFs to PNGs using imagemagick and comparing the images with P4Merge. This works quite fine even if it's a bit overcomplicated but at least I am getting an idea what might be wrong in the PDF.