Skip to content

Instantly share code, notes, and snippets.

@angusdev
Last active February 12, 2023 12:45
Show Gist options
  • Select an option

  • Save angusdev/b7e76d7d28ad5524fe43 to your computer and use it in GitHub Desktop.

Select an option

Save angusdev/b7e76d7d28ad5524fe43 to your computer and use it in GitHub Desktop.
Command line for frequently used pdftk command
#/bin/sh
# Command line for frequently used pdftk command
# Copyright 2014-2023 ellab.org
f2=$(basename "$2")
e2="${f2##*.}"
f2="${f2%.*}"
f3=$(basename "$3")
e3="${f3##*.}"
f3="${f3%.*}"
f4=$(basename "$4")
e4="${f4##*.}"
f4="${f4%.*}"
# if $3 is empty, use $2 to construct f3_2
f3_2=$3
if [ "$f3_2" == "" ]; then
f3_2="$f2.new.$e2"
fi
# if $4 is empty, use $2 and $3 to construct f4_23
f4_23=$4
if [ "$f4_23" == "" ]; then
f4_23="$f2+$f3.new.$e2"
fi
if [ "$1" == "cat" ]; then
echo "Combine $2 and $3 to $f4_23"
pdftk "$2" "$3" cat output $f4_23
elif [ "$1" == "col" ]; then
echo "Collate $2 and $3 to $f4_23"
pdftk A="$2" B="$3" shuffle A B output $f4_23
elif [ "$1" == "oddeven" ]; then
echo "Split $2 to ${f2}-odd.$e2 and ${f2}-even.$e2"
pdftk $2 cat 1-endodd output ${f2}-odd.$e2
pdftk $2 cat 1-endeven output ${f2}-even.$e2
elif [ "$1" == "dh" ]; then
echo "Delete first page of $2 to $f3_2"
pdftk "$2" cat 2-end output $f3_2
elif [ "$1" == "r1" ]; then
echo "Rotate $2 90 degrees clockwise to $f3_2"
pdftk "$2" cat 1-endE output $f3_2
elif [ "$1" == "r2" ]; then
echo "Rotate $2 180 degrees to $f3_2"
pdftk "$2" cat 1-endS output $f3_2
elif [ "$1" == "r3" ]; then
echo "Rotate $2 90 degrees anti-clockwise to $f3_2"
pdftk "$2" cat 1-endW output $f3_2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment