18

I have a about 500 folders with images inside. Is there a way I could batch convert this so that I get .pdf files that contain all images inside as pages?

EDIT:

There should be 500 PDF's created, each with the name of the containing folder, and each having images within it as pages.

Ska
  • 351

5 Answers5

22

On OS X

With Homebrew it's a snap to install ImageMagick:

brew install imagemagick

convert *.jpg output.pdf

and if the resulting PDF is a bit too big you can try:

convert -quality 60 *.jpg output.pdf

Linux, Unix, Windows

Of course ImageMagick can also be installed on other Unix systems, e.g. apt-get install imagemagick on Debian and Ubuntu. And even on Windows through GNU/Cygwin or Chocolately.

the
  • 2,929
16

OS X has several tools built in to automate image processing and PDF creation.

Just open up Automator.app, create a new Application.

Automator.app

Change it as shown below, by dragging the actions from the left pane to the right one.

Step one

  • Get Folder Contents with the Repeat… option enabled will get all your files, even from within the subdirectories.

  • New PDF from Images will create one PDF file on the desktop, each page consisting of one image.

Save the app somewhere (e.g. under /Applications or on your Desktop). Give it a proper name, like "Create PDF from Image.app". Then, you can drag your folders on its icon. Let the workflow do the job for you.


The above creates one single PDF file for all images. If you want to have one for each folder, that's going to be more complicated.

First, you need the Dispense Items Incrementally action. Install it. Then, open Automator again, and create a new Workflow (not an application).

Now, for convenience, you can download the workflow here. In case that link breaks, just change it as shown below:

Workflow screenshot

Or, in text form:

  • Get Selected Finder Items
  • Dispense Items Incrementally (the one we installed before)
  • Set Value of Variable, to remember the folder we're in
  • Get Folder Contents, to get the images
  • New PDF from images, to create the PDF. Here, take the variable from the "Variables" panel at the bottom and drag it to the "Save Output to…" field. This makes sure the PDF is created in the folder it belongs to. There's no easy way to rename the file other than setting a static file name. You could add a Rename Finder items action to set it though.
  • Loop, to begin from start and run with the next folder. You can disable the part where it asks for confirmation.

Save it as a Workflow, and now, here's how to execute it. Select your folders in Finder.

Finder screenshot

Then, go to Automator.app and click Run in the top right corner.


With 500 folders, that might take a while. Especially with high resolution pictures, your PDF might become huge. But you can try it on a smaller selection first and then let the workflow run until it's finished.

Chindraba
  • 2,058
slhck
  • 235,242
5

A more simple way is to view all the images in Preview, then print to PDF, very quick.

http://hints.macworld.com/article.php?story=20090119162659107

Shekhar
  • 5,139
risnandar
  • 150
2

On almost any system you'd be running this on your best solution may be ImageMagick. Available on *nix, Mac and Windows, supports both wildcarding (aka filename globbing) and specification of a list (e.g. @ImagesToProcess.txt) of input files, some advanced file specification options, a powerful command line, etc.

fencepost
  • 1,106
0

A solution that does not affect the quality of the original images is to use img2pdf.

This one-liner will recursively go through directories and make PDFs of the images there, naming the PDF the same as the directory, and adding "-JPG" before the file extension.

find . -type d | while read d; do img2pdf "${d}"/*.jpeg --output ./"${d}"/"${d##*/}-JPG.pdf"; done