-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamp
executable file
·37 lines (33 loc) · 876 Bytes
/
stamp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
#
# stamping letters with webstamp from swisspost v0.2
# 2013-07: fixes
# 2013-02: improvents
# 2012-12: initial release
# usage:
# ./stamp document.pdf[input] ws-file[ws-file]
# (c) 2013 by cyrill von wattenwyl
#
# check args
if [ ! -e "$1" ]; then
echo "usage ./stamp DOCUMENT STAMP"
exit 1
fi;
if [ ! -e "$2" ]; then
echo "usage ./stamp DOCUMENT STAMP"
exit 1
fi;
# how much pages has the given pdf?
NUMBER_OF_PAGES=`pdftk $1 dump_data | grep NumberOfPages | cut -d" " -f2`
#if longer than 1 site
if [ "$NUMBER_OF_PAGES" -ge "2" ]; then
pdftk $1 cat 1 output - | pdftk - stamp $2 output - | pdftk A=- B=$1 cat A1 B2-end output /tmp/ws-stamp-tmp
#just one site
else
pdftk $1 cat 1 output - | pdftk - stamp $2 output /tmp/ws-stamp-tmp
fi;
#move original file
_OFN=`basename $1 .pdf`
_ODN=`dirname $1`
mv $1 $_ODN/$_OFN.orig.pdf
mv /tmp/ws-stamp-tmp $1