2022-08-29 20:20:29 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
mkdir -p handbook
|
2022-08-29 20:56:32 +00:00
|
|
|
touch ./handbook/index.html
|
|
|
|
|
|
|
|
if [ ! -f ./handbook/cmunrm.otf ]; then
|
|
|
|
cd handbook
|
|
|
|
wget http://mirrors.concertpass.com/tex-archive/fonts/cm-unicode/fonts/otf/cmunrm.otf
|
|
|
|
base64 cmunrm.otf > cmunrm.txt
|
|
|
|
cd ..
|
|
|
|
fi
|
2022-08-29 20:20:29 +00:00
|
|
|
|
2022-08-31 20:26:18 +00:00
|
|
|
HANDBOOK="./handbook"
|
2022-08-29 20:20:29 +00:00
|
|
|
TMP_HTML="$(realpath ./handbook/index.html)"
|
|
|
|
HTML="html/index.html"
|
2022-08-29 20:56:32 +00:00
|
|
|
LAYOUT_PDF="handbook/layout.pdf"
|
2022-08-31 20:26:18 +00:00
|
|
|
BODY_HTML="handbook/body.html"
|
|
|
|
INDEX_TABLE_HTML="$(cat ./tmpl/handbook_index.html)"
|
|
|
|
|
|
|
|
rm -f "${BODY_HTML}"
|
|
|
|
|
|
|
|
WRITING=0
|
|
|
|
INDEX_TABLE=0
|
|
|
|
|
|
|
|
while read p; do
|
|
|
|
if [ ${WRITING} -eq 0 ] && [[ "${p}" == *"<body>"* ]]; then
|
|
|
|
WRITING=1
|
|
|
|
fi
|
|
|
|
if [ ${WRITING} -eq 1 ] && [[ "${p}" == *"</body>"* ]]; then
|
|
|
|
WRITING=0
|
|
|
|
fi
|
|
|
|
if [ ${INDEX_TABLE} -eq 0 ] && [[ "${p}" == *"class=\"indexTable\""* ]]; then
|
|
|
|
INDEX_TABLE=1
|
|
|
|
echo "${INDEX_TABLE_HTML}" >> "${BODY_HTML}"
|
|
|
|
fi
|
|
|
|
if [ ${INDEX_TABLE} -eq 1 ] && [[ "${p}" == *"</div>"* ]]; then
|
|
|
|
INDEX_TABLE=0
|
|
|
|
fi
|
|
|
|
if [ ${WRITING} -eq 1 ] && [ ${INDEX_TABLE} -eq 0 ]; then
|
|
|
|
echo "$p" >> "${BODY_HTML}"
|
|
|
|
fi
|
|
|
|
done < "${HTML}"
|
2022-08-29 20:20:29 +00:00
|
|
|
|
|
|
|
BODY_VAR="{{BODY_HTML}}"
|
|
|
|
TMPL_HTML=`cat tmpl/layout.html.tmpl`
|
2022-08-31 20:26:18 +00:00
|
|
|
BODY_CONTENT=`cat "${BODY_HTML}"`
|
2022-08-29 20:56:32 +00:00
|
|
|
FONT=`cat handbook/cmunrm.txt | tr -d '\n'`
|
2022-08-29 20:20:29 +00:00
|
|
|
|
2022-08-29 20:56:32 +00:00
|
|
|
BODY_CONTENT="${BODY_CONTENT//.svg/.jpg}"
|
2022-08-29 20:20:29 +00:00
|
|
|
ALL_HTML="${TMPL_HTML/$BODY_VAR/$BODY_CONTENT}"
|
2022-08-29 20:56:32 +00:00
|
|
|
ALL_HTML="${ALL_HTML/REPLACEFONT/$FONT}"
|
2022-08-29 20:20:29 +00:00
|
|
|
echo "${ALL_HTML}" > "${TMP_HTML}"
|
|
|
|
|
|
|
|
chromium-browser \
|
|
|
|
--headless \
|
|
|
|
--no-sandbox \
|
|
|
|
--disable-gpu \
|
|
|
|
--run-all-compositor-stages-before-draw \
|
|
|
|
--print-to-pdf-no-header \
|
2024-09-03 02:47:37 +00:00
|
|
|
--no-pdf-header-footer \
|
2022-08-29 20:20:29 +00:00
|
|
|
--no-margins \
|
|
|
|
--print-to-pdf="${LAYOUT_PDF}" \
|
|
|
|
"${TMP_HTML}"
|
|
|
|
|
|
|
|
cd handbook
|
|
|
|
|
2022-08-31 20:26:18 +00:00
|
|
|
rm -f page-*.jpg
|
|
|
|
|
2022-08-29 20:20:29 +00:00
|
|
|
#convert -density 600 "../${LAYOUT_PDF}" -quality 90 page-%3d.jpg
|
2022-08-31 20:26:18 +00:00
|
|
|
pdftoppm "../${LAYOUT_PDF}" page -jpeg -rx 600 -ry 600
|
|
|
|
|
|
|
|
convert -size 5100x6601 xc:white blank.jpg
|
|
|
|
|
|
|
|
cp blank.jpg page-0.jpg
|
|
|
|
cp blank.jpg page-00.jpg
|
|
|
|
|
|
|
|
pages=`ls page-*.jpg`
|
|
|
|
i=-1
|
|
|
|
for page in $pages
|
|
|
|
do
|
|
|
|
#5100x6601
|
|
|
|
if [ ${i} -gt 0 ]; then
|
|
|
|
echo "Numbering [$i] $page"
|
|
|
|
convert "${page}" -gravity North -pointsize 180 -draw 'text 0,6450 "'${i}'"' "${page}"
|
|
|
|
fi
|
|
|
|
let i=i+1
|
|
|
|
done
|
2022-08-29 20:20:29 +00:00
|
|
|
|
|
|
|
cd ..
|
2022-08-29 20:56:32 +00:00
|
|
|
#rm -f "${TMP_HTML}"
|
|
|
|
#rm -f "${LAYOUT_PDF}"
|