Question

I'm wanting to progress through a directory's subdirectories and either convert or place .TIF images into a pdf. I have a directory structure like this:

folder
   item_one
       file1.TIF
       file2.TIF
       ...
       fileN.TIF
   item_two
       file1.TIF
       file2.TIF
       ...
   ...

I'm working on a Mac and considered using sips to change my .TIF files to .PNG files and then use pdfjoin to join all the .PNG files into a single .PDF file per folder.

I have used:

for filename in *; do sips -s format png $filename --out $filename.png; done

but this only works for the .TIF files in a single directory. How would one write a shellscript to progress through a series of directories as well?

once the .PNG files were created I'd do essentially the same thing but using:

pdfjoin --a4paper --fitpaper false --rotateoversize false *.png

Is this a valid way of doing this? Is there a better, more efficient way of performing such an action? Or am I being an idiot and should be doing this with some sort of software, like ImageMagick or something?

Was it helpful?

Solution

Try using the find command with the exec switch to call your image conversion solution. Alternatively, instead of using the exec switch, you could pipe the output of find to xargs. There is lots of information online about using find. Here's one example from StackOverflow.

As far as the image conversion, I think that really depends on your requirements for speed and efficiency. If you've verified the process you described, and this is a one-time process, and it only takes seconds or minutes to run, then you're probably fine. On the other hand, if you need to do this frequently, then it might be worth investing the time to find a one-step conversion solution that takes less time than your current, two-pass solution.

Note that, instead of two passes, you may be able to pipe the output of sips to pdfjoin; however, that would require some investigation to verify.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top