Commit c47a94d2 authored by Christian Rohlfing's avatar Christian Rohlfing

- comments to splitting part in watermark.sh

parent da8c29e5
Pipeline #286748 passed with stages
in 1 minute and 34 seconds
......@@ -20,8 +20,8 @@ Options:
-o, --out output folder. Default: ./pdfs_watermarked
-c, --cores number of cores for parallel processing. Default: 1
-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
# -use return value from ${PIPESTATUS[0]}, because ! hosed $?
......@@ -31,8 +31,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
exit 1
fi
OPTIONS=hiocdsqv
LONGOPTS=help,in:,out:,cores:,dpi:,split,quality:,verbose
OPTIONS=hiocdqv
LONGOPTS=help,in:,out:,cores:,dpi:,splita3,quality:,verbose
# -regarding ! and PIPESTATUS see above
# -temporarily store output to be able to check for errors
......@@ -75,7 +75,7 @@ while true; do
quality="$2"
shift 2
;;
-s|--split)
--splita3)
split=y
shift 1
;;
......@@ -184,31 +184,48 @@ doit () {
exit
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 "Convert PDF into images"
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
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
page=$(basename "${longpage}")
mv "$longpage" "${tmpfolder}/tmppage_a3${page}"
done
pcnt=1
for longa3page in "${tmpfolder}"/tmppage_a3*.png; do
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
# 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)
numsinglepage=$(( numdoublepage*2 ))
......@@ -220,7 +237,7 @@ doit () {
numdest2=$(( pcnt ))
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
numdest1="00${numdest1}"
numdest1="${numdest1: -2}"
......@@ -242,6 +259,7 @@ doit () {
rm "$tmpfolder"/tmppage_*.png
fi ## split
# Watermarking
echo
echo "Watermarking"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment