Saturday, April 3, 2021

script to invert all pdf and result in folder

 @ECHO OFF

SETLOCAL EnableExtensions


SET OUTDIR=InvertedOutputs

SET GS=C:\Ghostscript\bin\gswin64c.exe


REM Make the output directory under the current one, hiding errors (e.g. directory exists)

MKDIR %OUTDIR% 1>nul: 2>>&1


REM Iterate through pdf files in current directory only.

REM Do not recurse child folders, since this would find files in the output directory

FOR %%F IN (*.pdf) DO Call :DoOne "%%F"


GOTO :Done


REM a subroutine eliminates the need for deferred expansion. All expansions are echoed to the console.

REM e.g. Call :DoOne "%%F" - processes one file

:DoOne

REM %~nx1 = the file name + extension of the argument. Since ~ strips quotes, they added back here.

REM including the commands 

REM -f %1 -- quotes are not used here, since %1 had to be quoted at the call site

ECHO ON

"%GS%" -o "%OUTDIR%\%~nx1" -sDEVICE=pdfwrite -c "{1 exch sub}{1 exch sub}{1 exch sub}{1 exch sub} setcolortransfer" -f %1

ECHO OFF

GOTO :EOF


:Done

Pause