Skip to content

Instantly share code, notes, and snippets.

@ManzDev
Last active November 1, 2019 11:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ManzDev/2072346fd65edce190d4 to your computer and use it in GitHub Desktop.
Save ManzDev/2072346fd65edce190d4 to your computer and use it in GitHub Desktop.
Reduce size PDF file (needs GhostScript)
@echo off
chcp 1252 >nul
set argc=0
for %%x in (%*) do set /a argc+=1
if [%argc%] == [0] goto syntax
if [%argc%] == [1] goto default
if [%argc%] == [2] goto param
:syntax
echo Sintaxis: %0 [options] [nombre.pdf]
echo.
echo Donde [options] puede ser:
echo.
echo /screen Tamaño optimizado para pantalla
echo /ebook Tamaño optimizado para ebooks
echo /printer Tamaño optimizado para impresión
echo /prepress Tamaño optimizado para imprenta de alta calidad
goto end
:default
echo Generando %~n1.min.pdf (puede tardar, dependiendo del tamaño del archivo)...
gswin32c.exe -q -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dBATCH -sOutputFile="%~n1.min.pdf" "%1"
goto end
:param
echo Generando %~n2.min.pdf (puede tardar, dependiendo del tamaño del archivo)...
gswin32c.exe -q -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=%1 -dNOPAUSE -dBATCH -sOutputFile="%~n2.min.pdf" "%2"
goto end
:end
@jorgied
Copy link

jorgied commented Feb 4, 2016

how do I send a pdf's folder as a parameter ?

@opexxx
Copy link

opexxx commented Jul 13, 2017

set GS_BIN=C:\Program Files\gs\gs9.21\bin\gswin64c.exe
set GS_OUTPUT_DIR=compressed
mkdir %GS_OUTPUT_DIR%
for %%i in (*.pdf) do "%GS_BIN%" -dNOPAUSE -dBATCH -dSAFER -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -sDEVICE=pdfwrite -sOutputFile="%GS_OUTPUT_DIR%%%i" "%%i"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment