From e1c031b851c62cd40cbc1b7bfabc1f04027cf0b2 Mon Sep 17 00:00:00 2001 From: Harsh Agrawal Date: Fri, 2 Sep 2022 00:20:46 +0530 Subject: [PATCH] Add utility script to pad a pdf with margins --- app/utils/add_margin.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 app/utils/add_margin.sh diff --git a/app/utils/add_margin.sh b/app/utils/add_margin.sh new file mode 100755 index 0000000..817f9d3 --- /dev/null +++ b/app/utils/add_margin.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e +if [[ -z $(which pdf-crop-margins) ]]; then + pip3 install -q pdfCropMargins; +fi; +if [[ -z $(which units) ]]; then + sudo apt install units +fi; + +infile=$(realpath $1) +outfile=$(realpath $2) +margin=${$3:-'6 mm'} +margin=$(units -t "$margin" "inch") + +margin=$(echo $margin*72| bc) +echo "Margin: " $margin +rand_str=$(echo $RANDOM | md5sum | head -c 8) +tmpfile="/tmp/${rand_str}.pdf" +pdf-crop-margins -o $tmpfile -p 100 -a4 -$margin -$margin -$margin -$margin $infile +pdfjam --outfile $outfile --paper a4paper $tmpfile