Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm surprised I couldn't find an easy script for this online. I have a directory with lots of subdirectories, each filled with TIFFs. How can I batch convert subfolders of multiple images (TIFFs) into single PDFs each named after their parent folders? CLI solution and ability to set output directory preferred

dir > 1998 > Jan011998 > 1.tif 2.tif ... → Jan011998.pdf (or, ideally, 1998-01.pdf)
dir > 1999 > 02231999 > 1.tif 2.tif ... → Feb231999.pdf (or 1999-02-23.pdf)

share|improve this question
irfanview can create the multi-page PDFs, but as far as I know it cannot be done from the command line. I suppose you could create a macro to do the job. AutoHotkey can do this, including sending the correct keystrokes into the application to drive it. – hdhondt Apr 17 '14 at 0:18… ? – Jasper Apr 17 '14 at 8:56
@Jasper: That's a start, but I'd need some sort of bash scripting or something to iterate through the bottom subdirectories (and I'm not sure how the batching would work either) – sean Apr 18 '14 at 11:54
are you on win or linux or sth. else? – Jasper Apr 18 '14 at 12:10
@Jasper: Mac, so UNIX is fine and I can run Windows through Parallels – sean Apr 19 '14 at 19:38

Here is a little script that should do the trick:


dirs=$(find . -type f -name "*.tiff" | xargs dirname |sort -u)

for d in $dirs; do
    #ls $d/*.tiff  # just debug info, should list all desired tiffs
    #echo $(cut -d/ -f3 <<<$d)  # debug info, should be desired output file name
    convert $d/*.tiff $(cut -d/ -f3 <<<$d).pdf


First, find is used to determine all directories that contain TIFF files. Then we use ImageMagick's convert to convert all TIFFs in each directory to a PDF file whose name is created from the directory. You can easily include a different output directory:

    convert $d/*.tiff somewhereElse/$(cut -d/ -f3 <<<$d).pdf
share|improve this answer

The pdftk (PDF toolkit) program allows you to combine multiple PDF files into one big output pdf file.

$ pdftk in1.pdf in2.pdf in3.pdf cat output big_out.pdf
share|improve this answer

Your Answer


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.