Showing posts with label PDF. Show all posts
Showing posts with label PDF. Show all posts

10/16/2019

Linux Compress PDF batch



#### gs
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf $INPUTFILE

### pdf2ps && ps2pdf
pdf2ps input.pdf output.ps && ps2pdf output.ps output.pdf

### Webservice
http://compress.smallpdf.com/de
For linux
#!/bin/sh
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile="compress_$@" "$@"
 ./compresspdf.sh file.pdf 
find -type f -name "*.pdf" -exec ./compresspdf.sh {} \;
#!/bin/sh
INPUT=$1; shift
OUTPUT=$1; shift
GS_BIN=/usr/bin/gs
QFACTOR="0.40"

# Image Compression Quality
#
# Quality HSamples VSamples QFactor
# Minimum [2 1 1 2] [2 1 1 2] 2.40
# Low     [2 1 1 2] [2 1 1 2] 1.30
# Medium  [2 1 1 2] [2 1 1 2] 0.76
# High    [1 1 1 1] [1 1 1 1] 0.40
# Maximum [1 1 1 1] [1 1 1 1] 0.15 

${GS_BIN} -dBATCH -dSAFER -DNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${OUTPUT} -c "<< /ColorImageDict << /QFactor ${QFACTOR} /Blend 1 /HSample [1 1 1 1] /VSample [1 1 1 1] >> >> setdistillerparams" -f ${INPUT}

For windows
echo off
:: PDF to PCL Converter. Needs Ghostscript locally, and installed here: "C:\Program Files\gs\gs9.02\bin\gswin32c.exe"
:: Other versions of GS will work, but the script will have to be updated.
:: Users can enter the breakpoint for the PCL files. If none is provided, 100 is used.
cls
echo This program will take all the PDF files in the current directory
echo and group them into PCL files. If you ran
echo this from the command line, you could enter the breakpoint for
echo number of PDF files per PCL. If left blank or not entered, the
echo program defaults to 100.
echo.
echo If you want to continue, hit any key and please wait for the
echo program to complete processing (could take a while).
echo If you want to stop now, hit CTRL-C and exit out of the batch.
pause

setlocal enabledelayedexpansion
set INC=%1
if "%1%" == "" set INC=100
SET GSS=
SET CTR=0
SET FL=1

for %%i in (*.pdf) DO (
SET GSS=!GSS! "%%i"
SET /a CTR+=1
echo !CTR! COUNTER !FL! OUTPUTFILE NUMBER
if !CTR! == %INC% (

"C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS!
echo "C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS!
set /a FL+=1
echo !FL! FL
set CTR=0
set GSS=

)

)
if NOT !CTR! == 0 (
echo LAST PROCESS
"C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS!
)


endlocal
echo Complete.
echo on