0

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

ex.
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)

Wolf
  • 2,340
  • 4
  • 18
  • 21
  • 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 00:18
  • http://superuser.com/questions/81290/batch-convert-tiff-images-to-pdf?rq=1 ? – Jasper Apr 17 '14 at 08: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) – Wolf 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 – Wolf Apr 19 '14 at 19:38

2 Answers2

0

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
RonJohn
  • 253
  • 2
  • 12
0

Here is a little script that should do the trick:

#!/bin/bash

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

done

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
Jasper
  • 908
  • 8
  • 17