-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.sh
executable file
·45 lines (37 loc) · 974 Bytes
/
main.sh
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
set -e
if [ -z "$1" ]; then
echo "Specify pdf to be extracted!"
exit 1
fi
current=$(dirname $0)
tmp="$current/tmp"
mkdir "$tmp" -p
# Crop pdf
echo "STEP: crop pdf"
echo "Started"
./crop.py "$1" "$tmp/cropped.pdf"
echo "Completed"
# Convert pdf to html
echo "STEP: extract pdf"
echo "Started"
pdf2txt.py -o "$tmp/cropped.html" -t html "$tmp/cropped.pdf"
echo "Completed"
# Tidy html
echo "STEP: tidy html"
echo "Started"
# NOTE: tidy return 1 on warning so just ignoring the return code
tidy -o "$tmp/tidy.html" -config "$current/tidyconf.txt" "$tmp/cropped.html" || echo ""
echo "Completed"
# Split large html into manageable chunks
echo "STEP: create html chunk"
echo "Started"
chunks="$tmp/chunks"
mkdir "$chunks" -p
csplit -n 5 -f "$chunks/" "$tmp/tidy.html" '/Page [0-9]/-1' '{*}'
echo "Completed"
# Add .html extension to chunks
echo "STEP: rename html chunk"
echo "Started"
cd "$chunks"
for f in *; do mv $f `basename $f `.html; done;
echo "Completed"