Wednesday, October 26, 2011

Batch convert PDFs to multipage TIFFs

Here's a powershell script that uses Ghostscript to convert a directory full of PDFs to multipage TIFF files.  This will convert all PDFs found in $input_path to a TIFF file that is placed in $output_path.  Note, the original file is then deleted.  Thanks to http://stackoverflow.com/questions/75500/best-way-to-convert-pdf-files-to-tiff-files/120316#120316

Set $tool to the correct path for Ghostscript and set $input_path and $output_path accordingly.



$tool = 'C:\Program Files (x86)\gs\gs9.02\bin\gswin32c.exe'
$input_path = 'C:\input\'
$output_path = 'C:\output\'
$pdfs = get-childitem $input_path -recurse | where {$_.Extension -match "pdf"}

foreach($pdf in $pdfs)
{

    $tiff = $output_path + $pdf.PSChildName.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
        Remove-Item $pdf.FullName
    }
}

1 comment:

Anonymous said...

Thanks for sharing knowledgeable blog which provide the information about the conversion of Batch convert PDFs to multipage TIFFs. Great blog!!

Multipage Tiff Convert