Skip to content

Instantly share code, notes, and snippets.

@richmont
Created September 26, 2023 04:15
Show Gist options
  • Save richmont/c86f361fc819944ee6d866c8f92994a1 to your computer and use it in GitHub Desktop.
Save richmont/c86f361fc819944ee6d866c8f92994a1 to your computer and use it in GitHub Desktop.
Compactar todos os PDFs de uma pasta usando Ghostscript e Powershell
$sourceFolder = "c:\origem"
$destinationFolder = "c:\destino"
$ghostscriptPath = "C:\Program Files\gs\gs10.02.0\bin\gswin64c.exe"
$pdfSettings = "/ebook"
Get-ChildItem -Path $sourceFolder -Filter "*.pdf" | ForEach-Object {
$outputFile = Join-Path -Path $destinationFolder -ChildPath $_.Name
$arguments = "-sDEVICE=pdfwrite", "-dCompatibilityLevel=1.4", "-dPDFSETTINGS=$pdfSettings", "-dNOPAUSE", "-dQUIET", "-dBATCH", "-sOutputFile=`"$outputFile`"", "`"$_`""
& $ghostscriptPath @arguments
Write-Host "Converting file: $($_.Name)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment