-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_pdf_overlay_footer
executable file
·61 lines (47 loc) · 1.45 KB
/
gen_pdf_overlay_footer
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
die() { printf %s "${@+$@$'\n'}" 1>&2 ; exit 1 ; }
see() ( { set -x; } 2>/dev/null ; "$@" )
dieifnotinpath() { command -v "$1" >/dev/null || die "$1 not in PATH"; }
#
# Usage:
# ./make_footer_watermark.sh "Left footer text" "Right footer text"
LEFT="$1"
RIGHT="$2"
cat <<'END_PS' > watermark.ps
%!PS
% Set page size to letter (612x792); adjust if needed
<< /PageSize [612 792] >> setpagedevice
/Helvetica findfont 12 scalefont setfont
% Bottom margin
36 dup translate % Move origin 36pt right, 36pt up
0 0 moveto
% We'll define a helper procedure to show text on the right side
% of the page. 'showright' is a custom operator that measures the string,
% then places it from the right margin minus 36pt.
/showright {
% 0 index => (string)
dup stringwidth pop % measure width
612 exch sub % 612 = page width; subtract string width
72 sub % subtract 72 for the right margin
0 moveto
show
} def
% Left text
(%LEFT_TEXT%) show
% Move to the same baseline, but we reset x
0 0 moveto
% Right text
(%RIGHT_TEXT%) showright
showpage
END_PS
# Replace placeholders with our 2 arguments (escape if necessary!)
sed -i "s|%LEFT_TEXT%|${LEFT}|" watermark.ps
sed -i "s|%RIGHT_TEXT%|${RIGHT}|" watermark.ps
# Use Ghostscript to produce a PDF
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/screen \
-o watermark.pdf \
-f watermark.ps
echo "Created watermark.pdf"