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 DS925+ which is this years model with 2.5G networking is only marginally more expensive. About £25 more on Amazon UK. Not sure on the certified disks thing though, I guess it depends if the disks they certified are more expensive than the others or not. I use Seagate IronWolfs personally. Are they on the list? I agree with Steven. Synology DSM is miles ahead of the competition, I wouldn't go elsewhere now. The price is justified.
    • Google Cloud announces new Gemini-powered tools to 'increase efficiency' for partners by David Uzondu Google just announced a couple of new AI tools for its Partner Network Hub on Google Cloud, designed to take care of some of the most boring admin work and make things a bit easier for the companies it works with. Putting together a formal Statement of Work can be a tedious process, where every single detail needs to be perfectly aligned with Google Cloud's requirements. The company's new SOW Analyzer, powered by Gemini, tackles this directly. Partners can upload their draft document, and the AI will immediately point out problems like missing clauses or technical goals that are not measurable, even providing examples of how to fix them. In addition to the analyzer, there is a new Bot-Assisted Live Chat. This is an AI agent built into the partner portal that provides 24/7 help with things like onboarding, billing questions, and incentive claims. If the AI cannot solve your problem with billing or rebate claims, it can hand you off to a human agent without making you explain the entire issue from scratch. These two tools are joined by AI-powered updates to the existing Earnings Hub, which is designed to help partners find new growth opportunities by using predictive data to show what services are in demand: The SOW Analyzer and Earnings Hub are available right now for partners in the hub. The Bot-Assisted Live Chat is currently rolling out and is expected to be fully available to all users by next month.
    • Not sure I agree with your particular interpretation of this. An ESU key is still required per device that you have to enter into the device in order to activate ESU. These aren't being given out for free. The linked Microsoft article still states: "If you have paid to enroll your remaining Windows 10 systems in the ESU program..." which seems to confirm this.
    • I swear, whoever is handling the Gundam IP for video games should be fired. How can you go from the gems that were releasing in PS1, PS2 and PS3, to the utter disaster that's today, from the VR game just to be on the hype bandwagon and all the focus on SD. This will probably be studied as one of the worst ways companies mishandle an IP.
  • Recent Achievements

    • Conversation Starter
      Kavin25 earned a badge
      Conversation Starter
    • One Month Later
      Leonard grant earned a badge
      One Month Later
    • Week One Done
      pcdoctorsnet earned a badge
      Week One Done
    • Rising Star
      Phillip0web went up a rank
      Rising Star
    • One Month Later
      Epaminombas earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      534
    2. 2
      ATLien_0
      207
    3. 3
      +FloatingFatMan
      171
    4. 4
      Michael Scrip
      148
    5. 5
      Steven P.
      121
  • Tell a friend

    Love Neowin? Tell a friend!