From: Christian Heller Date: Sun, 5 Mar 2023 22:54:46 +0000 (+0100) Subject: Add make_pbm_pdf.sh. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/todos?a=commitdiff_plain;h=5e1190e71b2ca2179861aa02802abc80b6d433d2;p=misc Add make_pbm_pdf.sh. --- diff --git a/make_pbm_pdf.sh b/make_pbm_pdf.sh new file mode 100755 index 0000000..2242921 --- /dev/null +++ b/make_pbm_pdf.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Extract PBMs from PDF and create new PDF from them. +set -e +n_pages=$(pdfinfo "$1" | grep -e '^Pages:' | awk '{ print $NF }') +i=1 +while [ "$i" -le "${n_pages}" ] +do + i_formatted=$( printf "%010d" $i) + prefix="pdfimages_export_${i_formatted}" + echo "extracting page $i as ${prefix}" + pdfimages "$1" -l $i -f $i "${prefix}" + rm *.ppm + source=$(ls -1 "${prefix}"* | head -1) + # negate to invert colours, rotate to, well, rotate + convert "${source}" -negate -rotate 270 "pdfimages_export_converted_${i_formatted}".pdf + rm *.pbm + i=$((i + 1)) +done +pdfunite "pdfimages_export_converted_"* "converted_$1" +rm pdfimages_export*