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

    • I would not mind paying 120 up to 150 dollars in this economy value of the dollar currency if their video game is quite breathtaking and excellent use of my hard earned work money. I think people need to appreciate all the effort workers and time that goes into excellent and worthy video games. Now if only the publishers and companies behind the video games would share the love with the developers those at the bottom of work making such games happen as in increase their money accounts and give them a more richer life that I wish would have happened . But how companies have bad reputation of being $$$ profit greedy I feel sad if there are any developers that feel unappreciated as in no real compensation for all the hours of work they put into a blockbuster hit . Have a great day everyone . Thank you developers engineers and programmers that make superb video games happen . You have my thanksgiving and I hope you really really appreciate my words . With you all about this
    • I guess they use the free version, which doesn't send money to any Russians.
    • True, you can pin it to the Start Menu, but my preference is to pin it to the Taskbar since I am using W11 on a desktop with a large display and a lot of space on the Taskbar.
    • 200 mph. Try going 200 mph with a vehicle on a street in any city in America. Good luck. Yes its speculation but so is the idea that it has been 100% approved by the government. When a new drug is under development it goes through a number of test phases, each of increasing efficacy and safety. I would imagine it is the same in this case. You can similuate real conditions on test roads with other cars and if successful on test roads you move it to the next test phase of testing it on real streets with human assistance if needed. Testing conditions on test roads can never account for all real life situations on real roads. This is what I imagine is happening now. The final test phase.
  • Recent Achievements

    • Week One Done
      Hartej earned a badge
      Week One Done
    • One Year In
      TsunadeMama earned a badge
      One Year In
    • Week One Done
      shaheen earned a badge
      Week One Done
    • Dedicated
      Cole Multipass earned a badge
      Dedicated
    • Week One Done
      Alexander 001 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      571
    2. 2
      ATLien_0
      185
    3. 3
      +FloatingFatMan
      183
    4. 4
      Skyfrog
      112
    5. 5
      Som
      106
  • Tell a friend

    Love Neowin? Tell a friend!