[SOLVED] Unable to do PDF comparison

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
NukaCola
Posts: 6
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

[SOLVED] Unable to do PDF comparison

Post by NukaCola » 2018-12-14T01:15:43-07:00

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:
viewtopic.php?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!
Last edited by NukaCola on 2018-12-17T04:57:54-07:00, edited 1 time in total.

snibgo
Posts: 11217
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unable to do PDF comparison

Post by snibgo » 2018-12-14T02:09:59-07:00

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".
snibgo's IM pages: im.snibgo.com

NukaCola
Posts: 6
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post by NukaCola » 2018-12-14T02:48:15-07:00

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.

snibgo
Posts: 11217
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unable to do PDF comparison

Post by snibgo » 2018-12-14T03:29:43-07:00

NukaCola wrote:convert: missing Null Image List Separator
Why are you still running "convert"?

What is your exact command?
snibgo's IM pages: im.snibgo.com

NukaCola
Posts: 6
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post by NukaCola » 2018-12-14T03:46:57-07:00

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.

snibgo
Posts: 11217
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unable to do PDF comparison

Post by snibgo » 2018-12-14T03:56:25-07:00

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:"?
snibgo's IM pages: im.snibgo.com

NukaCola
Posts: 6
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post by NukaCola » 2018-12-16T23:24:29-07:00

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?!

NukaCola
Posts: 6
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post by NukaCola » 2018-12-16T23:54:35-07:00

Is there a way to generate difference images? So that just the differences are visible after the comparison?

User avatar
fmw42
Posts: 24470
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unable to do PDF comparison

Post by fmw42 » 2018-12-17T00:02:39-07:00

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

NukaCola
Posts: 6
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post by NukaCola » 2018-12-17T04:57:11-07:00

Awesome, this works like a dream and is exactly what I needed.

Thank you both and have a great Christmas time!

snibgo
Posts: 11217
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: [SOLVED] Unable to do PDF comparison

Post by snibgo » 2018-12-17T05:37:58-07:00

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%.
snibgo's IM pages: im.snibgo.com

Post Reply