Link to home
Start Free TrialLog in
Avatar of JAVI1065
JAVI1065Flag for Puerto Rico

asked on

How can I convert from PDF to tiff using ghostscript?

I need to convert some files from pdf to tiff in a vb 2005 application and I heard it's possible with ghostscript. How can I approach this. I use vb but I can translate to c# if necessary.
ASKER CERTIFIED SOLUTION
Avatar of alainbryden
alainbryden
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try putting this CMD into the root of your ghostscript installation.

If it doesn't work then maybe ghostscript just can't do it.

~Alain
rem pdf2tif.cmd
rem Convert a pdf to a TIFF
rem Usage: pdf2tif.cmd input.pdf[output.tiff]
 
set GS_HOME=%~dp0
set GSC="%GS_HOME%bin\gsc.exe"
set fileinput=%1
set cmdfile="%GS_HOME%_%~n1.rsp"
if %2/==/ (set fileoutput="%~dp1%~n1%%d.tiff") else (set fileoutput=%2)
 
echo -q -dSAFER -dNOPAUSE -dBATCH > %cmdfile%
echo -sDEVICE#tifflzw -r600 -dTextAlphaBits=4 >> %cmdfile%
echo -dGraphicsAlphaBits=4 >> %cmdfile%
echo -sOutputFile#%fileoutput% -f %fileinput% >> %cmdfile%
%GSC% @%cmdfile%
 
if exist %cmdfile% erase %cmdfile%

Open in new window

apparently the following can also work from the command line.

~Alain
gswin32c -dNOPAUSE -q -g300x300 -sDEVICE=tiffg4 -dBATCH -sOutputFile=output_file_name.tif input_file_name.pdf

Open in new window

Here's more code that claims it can do the same using ghostscript in powershell:

~Alain
$tiff = $pdf.FullName.split('.')[0] + '.tiff'
if(test-path $tiff)
{
    "tiff file already exists " + $tiff
}
else        
{   
    'Processing ' + $pdf.Name        
        $param = "-sOutputFile=$tiff"
    & $tool -q -dNOPAUSE -sDEVICE=tiffg4 $param -r300 $pdf.FullName -c quit
}

Open in new window

Avatar of lglaw
lglaw

Here is a simple C# GS wrapper to convert PDF to JPEG which can easily be modified for TIFF:
http://www.mattephraim.com/blog/2009/01/06/a-simple-c-wrapper-for-ghostscript/
Change the sDevice arg from jpeg to tiffg4 (assuming you want black & white).  Lose dTextAlphaBits & dGraphicsAlphaBits.  You can use the -r arg to adjust dpi.
Avatar of JAVI1065

ASKER

I had to change of program