Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Minimize file size of embedded images in PDF output

$
0
0
Here's the code using Magick.NET
            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 pdf
convert.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.

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>