5

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)?

4
  • "downscale to 100dpi" - changing dpi does not affect the image size at all, merely how a page-layout app will treat it when placed. Could you clarify exactly what your method is?
    – Tetsujin
    Commented Jan 7, 2018 at 10:33
  • @Tetsujin, when I change DPI from 300 to 100 DPI, file size goes down from 2Mb to 150Kb. I'm not sure what you are asking about. Commented Jan 7, 2018 at 10:38
  • 2
    So it's downscaling the image, using dpi as your scale factor. It isn't actually doing what you think, but the end result is the same - reduction of image dimensions, not actual dpi. dpi is an 'imaginary' figure until you actually lay out a page, then it determines the size in relation to the page. Images have dimensions in pixels; that is the only absolute value.
    – Tetsujin
    Commented Jan 7, 2018 at 11:07
  • 1
    What steps do you take in preview to convert these images? Is it an automator workflow, print to PDF, export as PDF, something else? Perhaps it's your workflow that could be changed. There is a nice answer using ImageMagic but perhaps you can detail what specific steps you take so that other answers might be possible.
    – bmike
    Commented Jan 7, 2018 at 15:16

3 Answers 3

6

ImageMagic

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

magick -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

To install the free and open source ImageMagick, and the magick command line 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:

2

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.

1

On MacOS versions from Leopard (10.5) to Catalina (11), the Images to PDF Quick Action here will convert all selected images to one PDF document, without fitting to a page size or resampling the image.

On newer versions of the OS, you'll need to install python3 and use the script here, either as a standalone shell script (and the image files as arguments); or in an Automator or Shortcuts.app "Run Shell Script" action.

You can also use a script written in Swift in Monterey and later, though they are a bit slow compared to python.

2
  • The utility no longer seems to be available. I get a 404 page for github.com/benwiggy/PDFsuite/tree/master/Quick_Actions Commented Aug 21, 2022 at 9:20
  • 1
    @JulianHarty Sorry, I've rearranged the site, partly in response to Apple's removal of python, which has complicated the use of these scripts somewhat.
    – benwiggy
    Commented Aug 21, 2022 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .