Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
3  
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? –  Journeyman Geek Nov 29 '11 at 1:18
    
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 Nov 29 '11 at 1:44
add comment

4 Answers

up vote 13 down vote accepted

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

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

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

enter image description here

  • 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:

enter image description here

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.

enter image description here

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.

share|improve this answer
    
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 Nov 29 '11 at 15:22
    
@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 Nov 29 '11 at 16:09
    
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 Nov 29 '11 at 16:49
    
@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 Nov 29 '11 at 16:53
    
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 –  user130916 Apr 28 '12 at 22:01
add comment

Thanks to Homebrew:

brew install imagemagick

convert *.jpg output.pdf
share|improve this answer
    
Way faster than fidgeting with Preview! –  DK_ May 20 at 5:46
add comment

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

share|improve this answer
add comment

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|improve this answer
    
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 Nov 29 '11 at 1:51
    
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 –  fencepost Nov 29 '11 at 14:27
    
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 Nov 29 '11 at 15:06
    
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 Nov 30 '11 at 4:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.