Skip to content

Commit

Permalink
Add utility script to pad a pdf with margins
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh14901 committed Sep 1, 2022
1 parent c471c8e commit e1c031b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/utils/add_margin.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1c031b

Please sign in to comment.