RSS Feed


Comments RSS

DOS batch file to convert TIFF files to PDF

Here is a batch file I put together today for a coworker so he could easily convert TIFF format, .tif, files to PDF, .pdf, files. The batch file is put into the system environment PATH and a shortcut is put in the user profile ‘Send To’ folder, allowing the user to right click the .tif file and choose to send it as input to the batch file for conversion. The batch file requires the gnuwin32 utilities suite be installed and also listed in the system environment PATH. Installing these are well worth the time and effort as it freely brings the wealth of the GNU Utilities, that are the user space backbone of all Linux/Unix systems, to any Windows PC. They can be downloaded from here: The particular GNU utility we levarage to do the actual TIFF to PDF conver is called, understandably, tiff2pdf. Additionally, some interesting DOS batch techniques are used in parsing the input file path and file name, and also parsing out the base file name from its file extention. These involve the use of ~nx1 and ~dx1 as seen in the batch file that follows. Learn more about these techniques at the following site, in particular item #9:

So, here is the batch file. A DOS/GNU hybrid!

@echo off
REM usage: tiff2pdf.bat my_tiff_file.tif

REM get just the file name
set file=%~nx1

REM get just the working path of that file
set file_path=%~dp1

REM strip the file extension from the file name to prepare it for the processing command
set noext=%file:~0,-4%

REM call the GNU tiff2pdf utility with appropriate paramenters to convert from TIFF to PDF.
tiff2pdf.exe %1 -o “%file_path%%noext%.pdf” -f