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?".
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Unable to do PDF comparison

Post 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!
Last edited by NukaCola on 2019-03-20T05:26:02-07:00, edited 3 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unable to do PDF comparison

Post 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".
snibgo's IM pages: im.snibgo.com
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unable to do PDF comparison

Post by snibgo »

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: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unable to do PDF comparison

Post 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:"?
snibgo's IM pages: im.snibgo.com
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post 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?!
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post by NukaCola »

Is there a way to generate difference images? So that just the differences are visible after the comparison?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unable to do PDF comparison

Post 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
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post by NukaCola »

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

Thank you both and have a great Christmas time!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: [SOLVED] Unable to do PDF comparison

Post 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%.
snibgo's IM pages: im.snibgo.com
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: [SOLVED] Unable to do PDF comparison

Post 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.
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: [SOLVED] Unable to do PDF comparison

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unable to do PDF comparison

Post 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.
snibgo's IM pages: im.snibgo.com
NukaCola
Posts: 9
Joined: 2018-12-14T01:07:56-07:00
Authentication code: 1152

Re: Unable to do PDF comparison

Post 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.
Post Reply