Skip to main content

Reduce PDF Size on Multiple Documents with PowerShell and GhostScript

31 January, 2024
In this video I demonstrate how to compress the size of multiple PDF documents in a directory. I do this with PowerShell and GhostScript and achieve a 50% reduction without much loss in quality on the PDFs. Download GhostScript GhostScript Parameters: $parm = ” -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=144 -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile=$new ”

PowerShell Script:

$homedir = 'C:\Files\'

$pickup = $homedir+'\drop'
$completed = $pickup+'\compressed'

$ghost = "C:\Program Files\gs\gs9.50\bin\gswin64c.exe"

$pdfs = Get-ChildItem $pickup\*.pdf -File

foreach ($pdf in $pdfs){

    $new = $completed+'\compressed-'+$pdf.Name

    $parm = " -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dSubsetFonts=true -dColorImageDownsampleType=/Bicubic -dColorImageResolution=144 -dGrayImageResolution=144 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=144 -sOutputFile=$new "
    $Prms = $parm.Split(" ")

    & "$ghost" $Prms "$pdf" 

}