-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_pdf.sh
executable file
·60 lines (48 loc) · 1.32 KB
/
make_pdf.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
CHROME_TIMEOUT=180
SERVER_TIMEOUT=$CHROME_TIMEOUT
export TO_KILL_CHROME
export TO_KILL_PYTHON
cleanup(){
set +euo pipefail
kill "$TO_KILL_CHROME" "$TO_KILL_PYTHON"
}
set -euo pipefail
trap cleanup EXIT
# Cleanup old builds
rm -rf build/pdf
mkdir -p build/pdf
setup_chrome_dev_tools_env(){
pushd chrome-print-page-python
virtualenv-3 -p /usr/bin/python3 venv
set +euo pipefail # PS1 is not setup
. venv/bin/activate
set -euo pipefail
pip install -r requirements.txt
timeout $CHROME_TIMEOUT ./start_chrome.sh &
TO_KILL_CHROME="$!"
popd
}
start_tmp_http_server(){
pushd build/html
timeout $SERVER_TIMEOUT python -m http.server 8080 &
TO_KILL_PYTHON="$!"
popd
}
print_pdf(){
chrome-print-page-python/print_with_chrome.py --print_to build/pdf/book.pdf "http://localhost:8080/book.html"
}
main(){
# echo "COMMENT ME to run this script - v1.1 used FireFox to generate PDF!"
# exit 0
echo "-> PDF gen script start!"
setup_chrome_dev_tools_env
echo "-> Chrome started!"
start_tmp_http_server
echo "-> Python temporary http server started!"
echo "-> Printing PDF it might take some time"
print_pdf
echo "-> PDF gen script finished!"
echo "-> Killing Chrome $TO_KILL_CHROME and Python http server $TO_KILL_PYTHON"
}
main