Here's the code using Magick.NET
First I read in the PDFs and output pngs
using (MagickImageCollection new_images = new MagickImageCollection(),
old_images = new MagickImageCollection(),
diff_images = new MagickImageCollection())
{
new_images.Read(@"C:\Users\username\Pictures\projects\pdfcompare\new_drawing.pdf", settings);
old_images.Read(@"C:\Users\username\Pictures\projects\pdfcompare\old_drawing.pdf", settings);
int i = 1;
int j = 1;
foreach (MagickImage image in new_images)
{
image.Alpha(AlphaOption.Opaque);
i++;
}
foreach (MagickImage image in old_images)
{
image.Alpha(AlphaOption.Opaque);
j++;
}
// Compare both new and old
if (new_images.Count == old_images.Count )
{
for (int shtNum = 0; shtNum < new_images.Count; shtNum++)
{
MagickImage diff_image = new MagickImage();
MagickImage new_image = new_images.ElementAt(shtNum);
MagickImage old_image = old_images.ElementAt(shtNum);
new_image.Compare(old_image, Metric.FuzzError, diff_image);
diff_images.Add(diff_image);
}
}
// Output image diff
diff_images.Write(@"C:\Users\username\Pictures\projects\pdfcompare\output\diff-drawings" + ".pdf");
Here's the command line equivalent:First I read in the PDFs and output pngs
gswin64c.exe -q -dQUIET -dBATCH -dNOPAUSE -NOPROMPT -sDEVICE=png16m -r150 -sOutputFile="sheet-%d.png" "input.pdf"
Then I do the comparison and output the pdfconvert.exe sheet-1.png sheet-2.png output.pdf
I'm guessing the command line is smaller because I'm turning some pngs into a pdf. I'm not sure what file format gets wrapped by the pdf in Magick.NET + ghostscript. Could also be that I don't have an alpha channel in the command line version and I do with the code.