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

18

7

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

Posted 2011-11-29T01:16:21.743

Reputation: 341

3what 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? – Journeyman Geek – 2011-11-29T01:18:37.707

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 – 2011-11-29T01:44:35.100

Answers

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.

slhck

Posted 2011-11-29T01:16:21.743

Reputation: 182 472

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 – 2011-11-29T15:22:20.000

@Ska See my updated answer. Hope it works for you. This is where it gets tricky in Automator and where you'd think about rather moving to AppleScript or a simple Bash script in combination with AppleScript. – slhck – 2011-11-29T16:09:15.567

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? – Ska – 2011-11-29T16:49:45.833

@Ska yes, that's how you set the variable, but you can't use the variable in the output name of the PDF. At least not in an easy way. – slhck – 2011-11-29T16:53:36.933

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 – None – 2012-04-28T22:01:46.517

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.

kqw

Posted 2011-11-29T01:16:21.743

Reputation: 1 781

1+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! – Bill Cheatham – 2014-09-10T17:25:25.533

1This 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. – Giscard Biamby – 2015-04-12T14:59:52.103

3Way faster than fidgeting with Preview! – DK_ – 2014-05-20T05:46:39.390

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

risnandar

Posted 2011-11-29T01:16:21.743

Reputation: 150

This is the easiest way, since you can open a folder in Preview. See also: http://superuser.com/questions/350201/convert-many-images-to-one-pdf-on-mac

– David James – 2016-03-30T17:15:20.773

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

Posted 2011-11-29T01:16:21.743

Reputation: 1 086

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. – Ska – 2011-11-29T01:51:58.487

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: http://stackoverflow.com/questions/3243361/how-to-install-test-convert-resize-pdf-using-imagemagick-ghostscript-window . Still, the other answer is better for Macs

– fencepost – 2011-11-29T14:27:20.263

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 – 2011-11-29T15:06:47.297

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. – fencepost – 2011-11-30T04:18:30.073