From 5e1190e71b2ca2179861aa02802abc80b6d433d2 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 5 Mar 2023 23:54:46 +0100 Subject: [PATCH] Add make_pbm_pdf.sh. --- make_pbm_pdf.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 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* -- 2.30.2