Need helping making tiff2pdf command recursive


Recommended Posts

I have hundreds of multipage .tiff files that I would like to convert into .pdf files. I found a useful linux command to do that - tiff2pdf.

The problem is, it doesn't work recursively. Can anyone give me a hand in making a simple script that can recursively convert my tiff files to pdf? I can do bash scripts but I'm not go with "for each do x".

A sample directory structure is

Folder001

--001 truck.tiff

--001 cruse 1.tiff

--001 tank.tiff

Folder002

--002 truck.tiff

--002 banana.tiff

--002 city.tiff

--002 something.tiff

And I know the format of the command needs to be


tiff2pdf -o "FILENAME.PDF" "FILENAME.TIF"
[/CODE]

Any pointers on how I can do this or would anyone be willing to help me?

Make a PHP or Bash script to output all the filenames and then construct the command list from that.

e.g.

find . -name "*.tif"

Will get you a list of the tif files, then you just need to use Bash commands to change the extension from .tif to .pdf and put 2 arrays through the command


#!/bin/bash

# This is a simple script to search a directory for TIFF images and convert them to PDF.
# It relies on find, tiff2pdf, and egrep to work its magic.
# Files ending in '.tiff' or '.tif' (in any case) are supported.

if [ $# -ne 1 ]; then
echo "Syntax: $0 DIRECTORY_CONTAINING_TIFFS_TO_CONVERT"
exit 1
fi

dir_to_search=$1
if [ ! -d "$dir_to_search" ]; then
echo "ERROR! Invalid search directory \"$dir_to_search\""
exit 1
fi

tiffs=$(find "$dir_to_search" -type f -regextype 'posix-egrep' -iregex '.*\.tif[f]{0,1}$' -exec echo -n {}';' \;)

OLDIFS="$IFS"
IFS=';'

for tiff in $tiffs; do
echo $tiff | grep -qsiE '\.tif$'
if [ $? -eq 0 ]; then
extension_length=3
else
extension_length=4
fi
pdf="${tiff:0:$((${#tiff}-$extension_length))}pdf"

echo "tiff2pdf -o \"$pdf\" \"$tiff\""
tiff2pdf -o "$pdf" "$tiff"
done

IFS="$OLDIFS"

exit 0
[/CODE]

This topic is now closed to further replies.
  • Posts

    • the problem is a tip is VARIABLE you aren't guaranteed a specific income... just freaking pay your staff and set a fixed price for food
    • Operation Warp Speed Vaccine Summit - December 8, 2020 Donald Trump:  Thank you very much. Appreciate it very much. I’m honored to welcome doctors, scientists, industry executives, and state and local leaders to our historic Operation Warp Speed Vaccine Summit. It’s been some journey for all of us. It’s been an incredible success. We’re grateful to be joined by Vice President Mike Pence, who has done an absolutely incredible job on the Coronavirus Task Force. Mike, thank you. Stand up, Mike. (Applause.) Great job. We’re here to discuss a monumental national achievement. From the instant the coronavirus invaded our shores, we raced into action to develop a safe and effective vaccine at breakneck speed. It would normally take five years, six years, seven years, or even more. In order to achieve this goal, we harnessed the full power of government, the genius of American scientists, and the might of American industry to save millions and millions of lives all over the world. We’re just days away from authorization from the FDA, and we’re pushing them hard, at which point we will immediately begin mass distribution. Before Operation Warp Speed, the typical timeframe for development and approval, as you know, could be infinity. And we were very, very happy that we were able to get things done at a level that nobody has ever seen before. The gold standard vaccine has been done in less than nine months. And now this: Meghan McCain:  If you regret taking the shot, there's hope.  Buy this "Vaccine Detox"   🤣  
    • I haven't heard that sound in a while and now I kinda miss it.
    • Do we really expect home users to have access to enterprise licenses?
  • Recent Achievements

    • Apprentice
      Wireless wookie went up a rank
      Apprentice
    • Week One Done
      bukro earned a badge
      Week One Done
    • One Year In
      Wulle earned a badge
      One Year In
    • One Month Later
      Wulle earned a badge
      One Month Later
    • One Month Later
      Simmo3D earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      559
    2. 2
      ATLien_0
      258
    3. 3
      +FloatingFatMan
      182
    4. 4
      Michael Scrip
      125
    5. 5
      Steven P.
      104
  • Tell a friend

    Love Neowin? Tell a friend!