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,530

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