1

I am using ImageMagick's convert to combine 6 PNG files into a PDF:

Bytes   File name
-----   ---------
44927   002.png
43507   003.png
71375   004.png
56448   005.png
61696   006.png
57694   007.png

# Both generate a 533,378 byte PDF
convert 00?.png OutputFile.pdf
convert 00?.png -density 200x200 OutputFile.pdf

The images are 200 DPI black & white scans from a flatbed scanner. The PNG files total 335,647 KB, but the resulting OutputFile.pdf is 533,378 KB.

Is this size inflation due to re-rasterization?

How can one specify to convert to keep the existing pixels?

In case it matters, I am using Cygwin's ImageMagick 7.0.10.27-1 on Windows 10 64-bit (cygcheck -p convert | grep -i imagemagick).

user36800
  • 2,019
  • 2
  • 19
  • 34
  • The PNGS are already rasterized. But I suspect PDF will keep the raster images uncompressed as raw data (not formatted as PNGs) in the PDF vector shell. I do not know of any way to tell ImageMagick to keep them compress. You might look into other tools to convert raster images into PDF files – fmw42 Dec 06 '20 at 22:11
  • Thanks, but it seems that default compression occurs, just not enough to make up for the 8 bits per monochrome pixel. The investigation of other tools will take time, so I'm resorting to `convert` for convenience. I'll take the approximately 2x hit in file size. – user36800 Dec 09 '20 at 17:12

1 Answers1

0

The pdfimages output below that there is some default compression (under the ratio column). I recalled plumbing the depths of convert some time ago. The depth option did not reduce the bits per pixel. From the tests below, neither does depth in combination with monochrome. Additionally, it is odd that monochrome causes the DPI to change from 200 to 508 or 509.

One possible cause of file size inflation is the use if 8 bits/pixel. From the previous tests of convert linked to above, it seemed that the compression squeezed out space wasted by the unwanted 8 bits per pixel. From the PDF file sizes, however, it seem that if this is true, then it doesn't really make up for all of the file size inflation.

# 1st default, monochrome, 200dpi, depth 1, and combinations
convert 00?.png  default.pdf
convert -monochrome 00?.png mono.pdf
convert -monochrome 00?.png -density 200x200 mono200.pdf
convert -depth 1 00?.png  depth1.pdf
convert -monochrome -depth 1 00?.png  monoDepth1.pdf

ls -l *.pdf

   510362 default.pdf
   510350 mono.pdf
   510362 mono200.pdf
   510362 depth1.pdf
   510374 monoDepth1.pdf

for file in *.pdf ; do echo ' ' ; echo $file: ; pdfimages -list $file ; done

default.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%

mono.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%

mono200.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   508   508 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   508   508 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   508   509 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   508   508 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   508   508 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   508   509 85.2K 2.4%

depth1.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%

monoDepth1.pdf:
page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    1700  2167  gray    1   8  image  no         8  0   200   200 70.1K 1.9%
   2     1 image    1700  2145  gray    1   8  image  no        22  0   200   200 67.8K 1.9%
   3     2 image    1700  2139  gray    1   8  image  no        36  0   200   200 97.8K 2.8%
   4     3 image    1700  2156  gray    1   8  image  no        50  0   200   200 80.2K 2.2%
   5     4 image    1700  2156  gray    1   8  image  no        64  0   200   200 89.9K 2.5%
   6     5 image    1700  2150  gray    1   8  image  no        78  0   200   200 85.2K 2.4%
user36800
  • 2,019
  • 2
  • 19
  • 34