print_slides and a5ona4 updates

This commit is contained in:
Alexander Bocken 2022-11-14 10:00:29 +01:00
parent c9bf213963
commit 10fc3361fb
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8
2 changed files with 57 additions and 23 deletions

30
.local/bin/print_slides Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# install cups-pdf and install printer using the webinterface on http://localhost:631/admin
# default virtual printer dir is below, adjust if changed
VIRTUAL_PRINTER_DIR="/var/spool/cupsd-pdf/$USER"
# Printer to print magazine layout on
PRINTER="Canon-MF220"
for file in $@; do
lpr -P Virtual_PDF_Printer -o number-up=2 -o orientation-requested=4 -o fit-to-page -o media=a4 "$file"
str="."
until lpc status | grep -A 4 'Virtual_PDF_Printer:' | tail -n1 | grep 'no entries'; do
printf "\033[s\033[uPrinting to file for two slides per a5 page"
printf "%s" $str
printf "\033[u"
str=$str.
sleep 1
done
echo "virtual printing done."
last_job_id="$(ls "$VIRTUAL_PRINTER_DIR" | grep -o '[0-9]*\.pdf$' | grep '[0-9]' | cut -d'.' -f1 | sort -n | tail -n1)"
#echo "last_job_id:$last_job_id"
file_two_page="$(ls $VIRTUAL_PRINTER_DIR/*${last_job_id}.pdf)"
#echo "file_two_page:$file_two_page"
printf "Invoking a5ona4..."
a5ona4 "$file_two_page" > /dev/null
echo "Done."
rm "$file_two_page"
only_filename_two_page="$( echo "$file_two_page"| awk -F/ '{print $NS}' )"
echo "Magazine layout of $file being sent to printer..."
lpr -P $PRINTER -o media=A4 -o Duplex=DuplexTumble -o sides=two-sided-short-edge -o BindEdge=Bottom -o media=a4 -r a5ona4_$file*
done

View File

@ -1,24 +1,28 @@
#!/bin/sh
#!/bin/zsh
current="$(pwd)"
INPUTPDF="$1"
printf '\\documentclass[a4paper,final]{article}
\\usepackage{pdfpages}
\\usepackage{ifpdf,ifxetex,everyshi}
\\makeatletter
\\ifpdf
\\EveryShipout{\\ifodd\\c@page\\else\\pdfpageattr{/Rotate 180}\\fi}%%
\\fi
\\ifxetex
\\EveryShipout{\\ifodd\\c@page\\special{pdf: put @thispage << /Rotate 180 >>}%%
\\fi
}
\\fi
\\makeatother
\\begin{document}
\\includepdf[pages=-, nup=1x2, booklet=true, landscape]{%s}
\\end{document}' "$current/$INPUTPDF" > /tmp/tmp$$.tex
cd /tmp || exit
pdflatex /tmp/tmp$$.tex
mv /tmp/tmp$$.pdf "$current/a5ona4_$INPUTPDF"
cd "$current"
rm -f /tmp/tmp$$.log /tmp/tmp$$.log
for file in $@; do
INPUTPDF=/tmp/file.pdf
cp -f "$file" $INPUTPDF
printf '\\documentclass[a4paper,final]{article}
\\usepackage{pdfpages}
\\usepackage{ifpdf,ifxetex,everyshi}
\\makeatletter
\\ifpdf
\\EveryShipout{\\ifodd\\c@page\\else\\pdfpageattr{/Rotate 180}\\fi}%%
\\fi
\\ifxetex
\\EveryShipout{\\ifodd\\c@page\\special{pdf: put @thispage << /Rotate 180 >>}%%
\\fi
}
\\fi
\\makeatother
\\begin{document}
\\includepdf[pages=-, nup=1x2, booklet=true, landscape]{%s}
\\end{document}' "$INPUTPDF" > /tmp/tmp$$.tex
cd /tmp || exit
pdflatex /tmp/tmp$$.tex
only_filename="$(echo "$file" | awk -F/ '{print $NF}')"
mv /tmp/tmp$$.pdf "$current/a5ona4_$only_filename"
cd "$current"
rm -f /tmp/tmp$$.log /tmp/tmp$$.log
done