How to batch combine JPEG's from folders into PDF's

27,207

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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.

Share:
27,207

Related videos on Youtube

Ska
Author by

Ska

Updated on September 18, 2022

Comments

  • Ska
    Ska almost 2 years

    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.

    • Thalys
      Thalys over 12 years
      what OS? and do you want a CLI or GUI tool? Are the files named in a sane or consistant way, and is the order important?
    • Ska
      Ska over 12 years
      Mac OS X, it can be any sort of tool and I do own Acrobat Pro but I don't find that option. Files are alphabetically organised and I'd like to maintain that order. Thanks
  • Ska
    Ska over 12 years
    It would also require GhostScript and me doing the programming with who knows how many dependency management. I would assume there could be a simple tool that does that. After all the use case is rather simple.
  • fencepost
    fencepost over 12 years
    It shouldn't be that difficult - as long as you have both ImageMagick and GhostScript installed and ImageMagick able to find GS, you can just use the IM command line which makes it simple to script. This assumes that filename globbing will handle files in the correct order, but if not then it's going to be more complex anyway. For Windows, here's one guide to getting them working together: stackoverflow.com/questions/3243361/… . Still, the other answer is better for Macs
  • Ska
    Ska over 12 years
    Thanks for the awesome tips on IM, fencepost. You learn something new everyday. As for the original question, I will try the slhck's solution first.
  • Ska
    Ska over 12 years
    Amazing, however all the images are now in one PDF. Is it possible to make a separate PDF for each containing folder? I wasn't even aware of what all you can do with Automator, thanks a ton!
  • Ska
    Ska over 12 years
    Don't worry, I'll rename them later with bash script. However, wouldn't it be possible to create an Application which would pass the output of Get Folder Contents (folder name) and create a variable out of it?
  • fencepost
    fencepost over 12 years
    You're quite welcome. I posted not realizing that A) you were using a Mac and B) Ghostscript support on Macs is apparently significantly weaker for some reason - or at least it hasn't kept up with Windows and *nix.
  • Admin
    Admin about 12 years
    That is an awesome workflow. Thanks for the help on this. I have spent the past week decrypting JPGs of every issue of National Geographic back to the beginning of time and needed a way to convert all 250,000 pages to PDFs so that I can OCR them and make them searchable. You just saved me a ton of manual labor. One change I had to make on the script was to set a time out period greater than the default 0 minutes. Otherwise it only created one PDF. I did it with the manual loop, but that is way too much involvement in an automated process. I also told it to save them to a single folder so that
  • DK_
    DK_ about 10 years
    Way faster than fidgeting with Preview!
  • Bill Cheatham
    Bill Cheatham almost 10 years
    +1 I think the comparison between this and the accepted answer really shows the power of command line tools (and especially imagemagick) in this sort of situation!
  • Giscard Biamby
    Giscard Biamby about 9 years
    This is also possible in windows. If you are using chocolatey (package manager for windows): choco install imagemagick.tool, and then follow @KasperSouren's "convert" commands.
  • David James
    David James about 8 years
    This is the easiest way, since you can open a folder in Preview. See also: superuser.com/questions/350201/…