Skip to content
Snippets Groups Projects
Commit c47a94d2 authored by Christian Rohlfing's avatar Christian Rohlfing
Browse files

- comments to splitting part in watermark.sh

parent da8c29e5
Branches
Tags
No related merge requests found
Pipeline #286748 passed
...@@ -20,8 +20,8 @@ Options: ...@@ -20,8 +20,8 @@ Options:
-o, --out output folder. Default: ./pdfs_watermarked -o, --out output folder. Default: ./pdfs_watermarked
-c, --cores number of cores for parallel processing. Default: 1 -c, --cores number of cores for parallel processing. Default: 1
-d, --dpi dpi parameter for conversion from pdf to images. Default: 250 -d, --dpi dpi parameter for conversion from pdf to images. Default: 250
-s, --split flag to split A3 pages to A4 and resorts them -q, --quality quality parameter for jpeg. Default: 25
-q, --quality quality parameter for jpeg. Default: 25" --splita3 flag to split A3 landscape pages to A4 portrait pages and resorts them"
# -allow a command to fail with !’s side effect on errexit # -allow a command to fail with !’s side effect on errexit
# -use return value from ${PIPESTATUS[0]}, because ! hosed $? # -use return value from ${PIPESTATUS[0]}, because ! hosed $?
...@@ -31,8 +31,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then ...@@ -31,8 +31,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
exit 1 exit 1
fi fi
OPTIONS=hiocdsqv OPTIONS=hiocdqv
LONGOPTS=help,in:,out:,cores:,dpi:,split,quality:,verbose LONGOPTS=help,in:,out:,cores:,dpi:,splita3,quality:,verbose
# -regarding ! and PIPESTATUS see above # -regarding ! and PIPESTATUS see above
# -temporarily store output to be able to check for errors # -temporarily store output to be able to check for errors
...@@ -75,7 +75,7 @@ while true; do ...@@ -75,7 +75,7 @@ while true; do
quality="$2" quality="$2"
shift 2 shift 2
;; ;;
-s|--split) --splita3)
split=y split=y
shift 1 shift 1
;; ;;
...@@ -184,31 +184,48 @@ doit () { ...@@ -184,31 +184,48 @@ doit () {
exit exit
fi fi
# convert pdf into images # Convert PDF into images
# This may take a while depending on ${dpi}
# (which should not be set to a higher value than the DPI of the scanning device!)
echo echo
echo "Convert PDF into images" echo "Convert PDF into images"
pdftoppm -r ${dpi} -png $longinpdf "${tmpfolder}"/page pdftoppm -r ${dpi} -png $longinpdf "${tmpfolder}"/page
# Split # Split A3 pages
# scanning exams with the feeder of the copy machine results in double paged A3
# here, we split these A3 pages into two A4 ones and resort them accordingly
# which is the inverse of "brochure print"
if [[ "$split" = "y" ]]; then if [[ "$split" = "y" ]]; then
echo echo
echo "Split PDF A3 pages into A4" echo "Split landscape A3 pages into each two portrait A4 pages"
# rename a3 pages # rename A3 pages
for longpage in "${tmpfolder}"/page*.png; do for longpage in "${tmpfolder}"/page*.png; do
page=$(basename "${longpage}") page=$(basename "${longpage}")
mv "$longpage" "${tmpfolder}/tmppage_a3${page}" mv "$longpage" "${tmpfolder}/tmppage_a3${page}"
done done
pcnt=1 pcnt=1
for longa3page in "${tmpfolder}"/tmppage_a3*.png; do for longa3page in "${tmpfolder}"/tmppage_a3*.png; do
echo "${longa3page}" echo "${longa3page}"
# Split landscape A3 into two portrait A4 # Split landscape A3 page into two portrait A4 pages
convert "${longa3page}" -crop 50%x100% +repage "${tmpfolder}"/tmppage_a4_%02d.png convert "${longa3page}" -crop 50%x100% +repage "${tmpfolder}"/tmppage_a4_%02d.png
# Reorder # Reorder
# Example: 4 A3 pages, printed on both sides
# yields a brochure with 16 A4 pages
#
# 1st A3 page 2nd A3 page 3rd A3 page ... 8th A3 page
# |-----,-----| |-----,-----| |-----,-----| |-----,-----|
# |--16-,---1-| |---2-,--15-| |--14-,---3-| |---8-,---9-|
# |-----,-----| |-----,-----| |-----,-----| |-----,-----|
#
# results in
# 1st A4 2nd A4 ... 16th A4 page
# |-----| |-----| |-----|
# |---1-| |---2-| |--16-|
# |-----| |-----| |-----|
numdoublepage=$(find "${tmpfolder}"/ -type f -name "tmppage_a3*.png" | wc -l) numdoublepage=$(find "${tmpfolder}"/ -type f -name "tmppage_a3*.png" | wc -l)
numsinglepage=$(( numdoublepage*2 )) numsinglepage=$(( numdoublepage*2 ))
...@@ -220,7 +237,7 @@ doit () { ...@@ -220,7 +237,7 @@ doit () {
numdest2=$(( pcnt )) numdest2=$(( pcnt ))
fi fi
# Convert to %02d format # TODO: this must be simpler! # Convert to %02d format # TODO: this should be obtained simpler!
if [[ ${#numdest1} -lt 2 ]] ; then if [[ ${#numdest1} -lt 2 ]] ; then
numdest1="00${numdest1}" numdest1="00${numdest1}"
numdest1="${numdest1: -2}" numdest1="${numdest1: -2}"
...@@ -242,6 +259,7 @@ doit () { ...@@ -242,6 +259,7 @@ doit () {
rm "$tmpfolder"/tmppage_*.png rm "$tmpfolder"/tmppage_*.png
fi ## split fi ## split
# Watermarking # Watermarking
echo echo
echo "Watermarking" echo "Watermarking"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment