I have several pages imported from scanner in PNG format. I use image editor to clean some noise, downscale to 100PDI, convert image palette to grayscale, etc. Finally I've got a bunch of PNG images of small size, looking good at computer screen still.

Then I need to save these PNG pages to a single PDF file for distribution. Earlier I was able to achieve this using Preview.app. However in macOS X High Sierra 10.13 this approach does not work any longer because Preview.app is trying to downscale PNG images by 30% to fit page size. After this transform the image is not sharp enough any longer.

In earlier versions of macOS X Preview.app generated PDF file without transforming the images.

Is there a way to make a PDF file from a set of PNG images using these images as-is (without any transformation)?


ImageMagic

You can use ImageMagick to convert your PNG images to PDFs.

convert -density 100 sample.png sample.pdf

See How can I convert a PNG to a PDF in high quality so it's not blurry or fuzzy? for a related question and answers over on the Unix & Linux site.

Installing ImageMagick and convert

To install the free and open source ImageMagick, and the included convert tool, you can use the Homebrew project.

Once brew is installed, use the following command to install ImageMagick:

brew install imagemagick

Online Services

Alternatively, you can use a web service to perform the conversion for you. Search for convert png to pdf to find such services:

  • http://png2pdf.com
  • https://www.zamzar.com/convert/png-to-pdf
  • https://cloudconvert.com/png-to-pdf

Looking for a specialised tool that fits exactly into the workflow described, avoiding some pitfalls other command line options may present, is

img2pdf

Lossless conversion of raster images to PDF. You should use img2pdf if your priorities are (in this order):

  1. always lossless: the image embedded in the PDF will always have the exact same color information for every pixel as the input
  2. small: if possible, the difference in filesize between the input image and the output PDF will only be the overhead of the PDF container itself
  3. fast: if possible, the input image is just pasted into the PDF document as-is without any CPU hungry re-encoding of the pixel data

Conventional conversion software (like ImageMagick) would either:

  1. not be lossless because lossy re-encoding to JPEG
  2. not be small because using wasteful flate encoding of raw pixel data
  3. not be fast because input data gets re-encoded

Another advantage of not having to re-encode the input (in most common situations) is, that img2pdf is able to handle much larger input than other software, because the raw pixel data never has to be loaded into memory.

This is a free/libre and small python tool with minimal dependencies. If you already have pip installed then a simple pip3 install img2pdf takes care of 'getting it'.

Usage is then straightforward:

$ img2pdf img1.png img2.jpg -o out.pdf

Depending on your habits, you type img2pdf in Terminal, you can then select all your PNGs in Finder and just drag&drop them into the Terminal window, add the -oand add the desired name for the output file.