Revert "On second though, shell script should not have .sh extension for simplicity"

This reverts commit 249eb79fc9.
This commit is contained in:
otthorn 2021-02-16 00:54:05 +01:00
parent 303f030351
commit 54f5237c74
2 changed files with 100 additions and 114 deletions

View file

@ -7,9 +7,9 @@ You need to have ghoscript installed on your machine.
``` ```
git clone https://gitea.auro.re/otthorn/pdf-optimize git clone https://gitea.auro.re/otthorn/pdf-optimize
cd pdf-optimize cd pdf-optimize
chmod +x pdf-optimize chmod +x pdf-optimize.sh
sudo mkdir -p /opt/bin/ sudo mkdir -p /opt/bin/
sudo cp pdf-optimize /opt/bin/ sudo cp pdf-optimize.sh /opt/bin/pdf-optimize
``` ```
Don't forget to add `/opt/bin` to your `PATH`. Don't forget to add `/opt/bin` to your `PATH`.

View file

@ -19,18 +19,11 @@ function usage
{ {
echo "usage: pdf-optimize [options] input.pdf" echo "usage: pdf-optimize [options] input.pdf"
echo " "; echo " ";
echo " -a | --archive : archive mode (PDF/A)";
echo " -c | --compatibility : compability more with PDF 1.4";
echo " -h | --help : print this message";
echo " -k | --quality : choose quality profile from:
* 1 HIGH QUALITY [default]
* 2 LOW QUALITY
* 3 AGGRESSIVE
* 4 VERY AGGRESIVE";
echo " -o | --output : output filename"; echo " -o | --output : output filename";
echo " -q | --quiet : run quietly"; echo " -q | --quiet : run quietly";
echo " -v | --verbose : run verbosly"; echo " -v | --verbose : run verbosly";
echo " -y | --yes-to-replace : yes to replace existing files"; echo " -y | --yes-to-replace : yes to replace existing files";
echo " -h | --help : print this message";
echo " "; echo " ";
echo "If no output path is specified, given input.pdf as input will output echo "If no output path is specified, given input.pdf as input will output
input_compressed.pdf" input_compressed.pdf"
@ -48,10 +41,7 @@ function arg_parse
while [ "$1" != "" ]; do while [ "$1" != "" ]; do
case "$1" in case "$1" in
-k | --quality ) quality="$2"; shift;;
-o | --output ) output_path="$2"; shift;; -o | --output ) output_path="$2"; shift;;
-a | --archive ) archive=1;;
-c | --compatibility ) compatibility=1;;
-q | --quiet ) quiet=1;; -q | --quiet ) quiet=1;;
-v | --verbose ) verbose=1;; -v | --verbose ) verbose=1;;
-y | --yes-to-replace ) replace=1;; -y | --yes-to-replace ) replace=1;;
@ -105,36 +95,32 @@ function run
${bold}$output_path${normal}." ${bold}$output_path${normal}."
fi fi
# define the base command # run the compression using ghostscript
base_command=" if [[ "$verbose" != 1 ]]; then
gs -sDEVICE=pdfwrite \ ghostscript -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/prepress \ -dPDFSETTINGS=/prepress \
-dNOPAUSE \ -dNOPAUSE \
-dBATCH "; -dQUIET \
-dBATCH \
# add compatibilty -sOutputFile=$output_path \
if [[ "$compatibility" == 1 ]]; then $input_path
base_command+="-dCompatibilityLevel=1.4 "; else
echo "input_path=$input_path";
echo "output_path=$output_path";
echo "quiet=$quiet";
echo "verbose=$verbose";
echo "replace=$replace";
echo " ";
ghostscript -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/prepress \
-dNOPAUSE \
-dBATCH \
-sOutputFile=$output_path \
$input_path
fi fi
# ask ghostsript to be quiet
if [[ "$verbose" == 1 ]]; then
base_command+="-dQUIET ";
fi
# add archive mode option
if [[ "$archive" == 1 ]]; then
base_command+="-dPDFA=2 -dPDFACompatibilityPolicy=1 "
fi
# add input and ouput paths
base_command+="-sOutputFile=$output_path \
$input_path"
# run command
echo $base_command;
#eval $base_command;
# catching errors # catching errors
if [[ "$?" != 0 ]]; then if [[ "$?" != 0 ]]; then
echo "Something went wrong with ghostscript."; echo "Something went wrong with ghostscript.";
@ -144,7 +130,7 @@ ${bold}$output_path${normal}."
# compute the compresion rate # compute the compresion rate
if [[ "$quiet" != 1 ]]; then if [[ "$quiet" != 1 ]]; then
#compute_compression; compute_compression;
fi fi
} }