-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility script to pad a pdf with margins
- Loading branch information
1 parent
c471c8e
commit e1c031b
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |