Search This Blog

Saturday 11 April 2009

Convert TIFF to PDF

A request we often get is a way to convert TIFF files to PDF with WatchDirectory.

While WD does not have a native way to do this, you should be aware that WD's "Automatically Run a Batch File" plugin can do almost anything. If there is a command line tool available, WatchDirectory can "run it".

Anyway, we have found 2 ways to convert TIFF to PDF using command line tools. The batch scripts below should be started by WD's "run a batch file" plugin. It is also a good idea to create a filter so WD will only start the script for TIF and TIFF files.

ImageMagick and Ghostscript

ImageMagick is one of my favorite tools for image manipulation. If a format is not "natively" supported by ImageMagick, it can delegate to other tools. ImageMagick needs Ghostscript for PDF support.

Downloads needed:
ImageMagick, I currently use v6.5.1, available here: http://www.imagemagick.org/script/binary-releases.php#windows.
Ghostscript, I currently use v8.6.3, available here: http://mirror.switch.ch/ftp/mirror/ghost/GPL/gs863/.

The ImageMagick/Ghostscript script. Note you don't see any reference to Ghostscript, but it must be installed otherwise the script won't work.

@echo off
IF "%WD_FILE_E%" NEQ "TIF" (
   IF "%WD_FILE_E%" NEQ "TIFF" GOTO :EOF
)
rem where is ImageMagick installed???
SET IMADIR=C:\Program Files\ImageMagick-6.5.1-Q16

"%IMADIR%\convert.exe" "%WD_FILE%" "%WD_FILE_D%\%WD_FILE_B%.pdf"
IF %ERRORLEVEL% NEQ 0 GOTO :EOF

rem if you want to remove the tiff after it has been converted
rem uncomment (remove the "rem") the next line
rem DEL "%WD_FILE%"

Irfanview

Another great tool, I didn't even know it supported command line conversions until Dirk (German language support) told me. You can download Irfanview here.

The Irfanview script:

@echo off
IF "%WD_FILE_E%" NEQ "TIF" (
   IF "%WD_FILE_E%" NEQ "TIFF" GOTO :EOF
)
rem where is Irfanview installed???
SET IMADIR=C:\Program Files\irfanview

"%IMADIR%\i_view32.exe" "%WD_FILE%" /convert="%WD_FILE_D%\%WD_FILE_B%.pdf"
IF %ERRORLEVEL% NEQ 0 GOTO :EOF

rem if you want to remove the tiff after it has been converted
rem uncomment (remove the "rem") the next line
rem DEL "%WD_FILE%"

IrfanView settings

Current releases of IrfanView will prompt you with a little popup window (to preview the PDF). Obviously, you don't want that when you are automating the creation of PDF files.

Just start IrfanView, open a TIFF file and save it as PDF. Next to the "Save As" window, where you enter the pdf filename, is a little window where you should select the "not needed" option. From now on, the script above will not cause those prompts.

No comments: