technical architecture.

Archive for April, 2010

Recursive Tiff to PDF

by on Apr.01, 2010, under Admin, Batching, utility

Another one of those semi random requests that turned out to be more of a pain in the arse than it really should be. the mission: Converting a large mass of scanned tiff CAD drawings into multi page PDF’s

There are two ways to do this fairly quickly, the easy way if you don’t have many individual sets to work with is to simply drag all the tif images into the window in Acrobat Pro and save the file from there.

If however, like us, you have to convert 42 gigs or so of tiff’s spread across 204 folders and group the PDF’s by the folders, you can programmatically do it via some batch scripting and the use of a few free command line utilities from the internet.

First thing to do is convert each individual TIF file to a PDF, for this, we use Imagemagick this is a tool that can do many things but we’re really just going to abuse the ‘convert’ application for now.

After installation, you can then in the dos prompt type ‘convert file.tif file.pdf’

For our purposes we want to convert ALL of the files, so we can set it up in a recursive for loop using

Saved into a file “Convert all Tiffs in Subdirectory to PDFs.bat” or something equally exciting:
FOR /R %%a IN (*.tif) DO convert "%%a" "%%a.pdf"

After that is done we will use a second utility to ‘join’ the pdf’s the PDF toolkit

With this util we can modify pdf files quickly; we’ll use the Append function

pdftk *.pdf cat output combined.pdf

This will concatenate all pdf’s in the current directory and write them into ‘combined.pdf’ in the same directory. Great!

To expand this into a large subdirectory we do a little more batch scripting

The below is saved into a file “Join all PDF in directory tree.bat”

FOR /F "delims=" %%a in ('DIR /S /B /AD ^|SORT') DO (
CD "%%a"
pdftk *.pdf cat output "%%a_joined.pdf"

This will output a combined PDF for each of the individual directories.

A good time was had by all.

Imagemagick looks to have quite a few useful applications and will warrant some more exploration soon.

1 Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!