Wednesday, December 03, 2008

Convert PDF to TIFF - Using Ghost Script

Requirement : To convert any PDF to TIFF.
Solution: In an enterprise during the day to day activities, back operations and other teams come across requirements to convert a file from one format to another. Converting TIFF to PDF and vice versa is one of the example.

TIFF to PDF
If you are a non technical staff you may contact the software provider team in your organization and get access to the tool which does TIFF to PDF conversion. But if you are a technical person (programmer) then you can leverage iText library and write an application to achieve this. As iText is free so its easy to save yourself from licensing costs and other licensing related obligations.

PDF to TIFF
There are various scenarios where you might need to convert file from PDF to TIFF format. For example you may get some document from lender or broker in PDF format containing some sensitive information. Suppose as a part  of your process requirement you need to save only TIFF files containing no sensitive information so you have to go through two step process:
1). Convert PDF to TIFF
2). Remove the sensitive information

Here we are going to discuss the tool 'GhostScript' which helps in achieving first step. Installation of GhostScript :
Step 1: Download GhostScript by visiting the below link
http://mirror.cs.wisc.edu/pub/mirrors/ghost/GPL/gs863/gs863w32.exe
Step 2: You can install this anywhere on your computer. For tutorial purpose I am using C:\Program Files\gs

The main file we are interested in is gswin32c which can be found in C:\Program Files\gs\gs8.63\bin folder. You can use this executable to perform the conversion either by running it at command prompt or inserting the following command in a batch (.bat) file and then executing it.

command 1 : cd C:\PROGRA~1\gs\gs8.63\bin
command 2: gswin32c -dBATCH -dNOPAUSE -sDEVICE=tiffg4 -r300x300 -sOutputFile=%2 %1
Here is the explanation each switch/option we have used in the above example :

sDEVICE = Type of Tiff
-r300x300 = DPI settings
-dNOPAUSE 
Disables the prompt and pause at the end of each page. Normally one should use this (along with -dBATCH) when producing output on a printer or to a file; it also may be desirable for applications where another program is "driving" Ghostscript.  

-dBATCH
Causes Ghostscript to exit after processing all files named on the command line, rather than going into an interactive loop reading PostScript commands. Equivalent to putting -c quit at the end of the command line.
For more information visit http://pages.cs.wisc.edu/~ghost/doc/cvs/Use.htm#Output_device http://www.ghostscript.com/ http://en.wikipedia.org/wiki/Ghostscript