Taking this answer as starting point
- Split and extract informations from the multipage
pdftk input.pdf burst
- Split each page
pw=$(cat doc_data.txt | grep PageMediaDimensions | head -1 | awk '{print $2}')
ph=$(cat doc_data.txt | grep PageMediaDimensions | head -1 | awk '{print $3}')
hph=$(( ph / 2 ))
wpx=$(( pw*10 ))
hpx=$(( hph*10 ))
for f in pg_[0-9]*.pdf ; do
tf=top_$f
bf=bottom_$f
gs -o ${bf} -sDEVICE=pdfwrite -g${wpx}x${hpx} -c "<</PageOffset [0 0]>> setpagedevice" -f ${f}
gs -o ${tf} -sDEVICE=pdfwrite -g${wpx}x${hpx} -c "<</PageOffset [0 -${hph}]>> setpagedevice" -f ${f}
done
- Join
pdftk top_pg_0001.pdf bottom_pg_0001.pdf top_pg_0002.pdf bottom_pg_0002.pdf ... cat output output.pdf
- Rotate
pdftk output.pdf cat 1-endeast output outputRotated.pdf
awk
can do all ofgrep
,cat
,head
and arithmetic operations. – Stéphane Chazelas Aug 06 '23 at 19:08