-
Notifications
You must be signed in to change notification settings - Fork 1
/
pdfinteractive
executable file
·133 lines (117 loc) · 2.75 KB
/
pdfinteractive
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#
# operate on a point or rectangle of a pdf file
# emphasize
# clip all pages
# erase rectangle (draw in white)
# cover rectangle (draw in black)
# write text
#SIMULATE=echo
# tty settings
clear
PREVSTTY=$(stty -g)
onexit() {
setterm --cursor off
stty $PREVSTTY
}
trap onexit EXIT
stty icrnl onlcr echo icanon
setterm --cursor on
# arguments
echo "$@"
KEY="$1"
ID="$2"
FILE="$3"
PAGE="$4"
BOXNUMBER="$5"
SCROLLX="$6"
SCROLLY="$7"
TOTPAGES="$8"
TEXTBOX="$9"
DEST="${10}"
RECT="${11}"
[ $RECT = '[]' ] && RECT="$TEXTBOX"
echo $RECT
# coordinates
X0=$(echo "$RECT" | cut -d, -f1 | cut -d[ -f2)
Y0=$(echo "$RECT" | cut -d, -f2 | cut -d- -f1)
X1=$(echo "$RECT" | cut -d- -f2 | cut -d, -f1)
Y1=$(echo "$RECT" | cut -d, -f3 | cut -d] -f1)
CORNER="[$X0,$Y0]"
echo "file $FILE"
echo "page $PAGE"
echo "box $RECT"
echo "corner $CORNER"
# output file
BASE=${FILE%%.pdf}
BASE=${BASE%%-edit-*}
EDIT=${BASE}-edit-%d.pdf
I=1
while [ -f $(printf $EDIT $I) ];
do
I=$((I+1))
done
OUT=$(printf $EDIT $I)
TEMP=$(printf "${BASE}-temp-%d.pdf" $I)
echo $OUT
# commands
COMMANDS='emphasize clip_page clip fit erase cover exit'
[ $X0 = $X1 ] && [ $Y0 = $Y1 ] && COMMANDS='write red exit'
N=$(echo $COMMANDS | wc -w)
# operate on file
PS3="choose command [1-$N]: "
select COMMAND in $COMMANDS;
do
case $COMMAND in
emphasize)
echo emphasize "$RECT" of page "$PAGE" of file "$FILE"
$SIMULATE \
pdfdrawover "$FILE" output "$OUT" page "$PAGE" \
color [1.0,0.0,0.0,0.5] filledbox "$RECT";;
clip_page)
echo clip page "$RECT" of page "$PAGE" of file "$FILE"
$SIMULATE \
pdfdrawover "$FILE" output "$OUT" page "$PAGE" \
emptypage clip "$RECT" paste;;
clip)
echo clip "$RECT" of page "$PAGE" of file "$FILE"
$SIMULATE \
pdfdrawover "$FILE" output "$OUT" \
emptypage clip "$RECT" paste;;
fit)
echo fit "$RECT" of file "$FILE"
$SIMULATE \
pdfdrawover "$FILE" output "$TEMP" \
emptypage clip "$RECT" paste
$SIMULATE \
pdffit -o "$OUT" -x "$RECT" "$TEMP"
rm -f "$TEMP";;
erase)
echo erase "$RECT" of page "$PAGE" of file "$FILE"
$SIMULATE \
pdfdrawover "$FILE" output "$OUT" page "$PAGE" \
color white filledbox "$RECT";;
cover)
echo cover "$RECT" of page "$PAGE" of file "$FILE"
$SIMULATE \
pdfdrawover "$FILE" output "$OUT" page "$PAGE" \
filledbox "$RECT";;
red) COLOR="color [1.0,0.0,0.0]";&
write)
echo write at "$CORNER" in page "$PAGE" of file "$FILE"
echo -n "string to write: "
read S
$SIMULATE \
pdfdrawover "$FILE" output "$OUT" page "$PAGE" \
$COLOR moveto "$CORNER" print "$S";;
exit)
echo -n "unchanged" 1>&3
echo 0 > pdfinteractive-ret.txt
exit 0;;
esac
break
done
echo "$PAGE $BOXNUMBER $SCROLLX $SCROLLY" 1>&3
echo -n "$OUT" 1>&3
echo 3 > pdfinteractive-ret.txt
exit 3