Created
September 26, 2023 04:15
-
-
Save richmont/c86f361fc819944ee6d866c8f92994a1 to your computer and use it in GitHub Desktop.
Compactar todos os PDFs de uma pasta usando Ghostscript e Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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