-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathachari.sh
executable file
·131 lines (107 loc) · 3.21 KB
/
achari.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
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
#!/bin/bash
function logo(){
cat << "EOF"
___ _ _
/ _ \ | | (_)
/ /_\ \ ___| |__ __ _ _ __ _
| _ |/ __| '_ \ / _` | '__| |
| | | | (__| | | | (_| | | | |
\_| |_/\___|_| |_|\__,_|_| |_|
EOF
echo "Version: 0.1.0 beta"
echo "Developed by: Christian Kisutsa"
echo ""
}
#+++++++
#ACHARI
#+++++++
#Check if option and codes file has been provided
if ! [ "$1" ] || [ "$1" == '-h' ] || [ "$1" == '--help' ] || ! [ "$2" ]; then
logo
echo "Usage:"
echo "[options] <path/to/keep_note/folder>"
echo ""
echo "Options:"
echo "-p, --pdf - convert notes to PDF"
echo "-i, --png - convert note to PNG file"
echo "-h, --help - print this help"
echo ""
echo "Example:"
echo "Convert to PDF e.g $0 --pdf </full/path/to/keep_note/folder>"
echo "Convert to PNG e.g $0 --png </full/path/to/keep_note/file>"
exit -1
fi
#++++++++++++++++++++
#Convert HTML to PDF
#+++++++++=++++++++++
if [ $1 == '-p' ] || [ $1 == '--pdf' ] ; then
logo
echo "==================="
echo " Converting to PDF "
echo "==================="
echo "[-]Enter PDF title:"
read pdf_title
echo ""
echo "[-]Enter PDF file name: (without whitespace and .pdf)"
read pdf_name
echo ""
echo "[-]Setting up environment..."
mkdir -p buffer/
touch buffer/pages.txt
touch buffer/images.txt
echo ""
#Find the necessary html files
echo "[-]Listing files to convert..."
find $2 -name "page*" -type f -exec ls {} \; | sort -V | tee buffer/pages.txt
echo ""
echo "[-]Listing images to convert..."
find $2 -name "*png" -type f -exec ls {} \; | sort -V | tee buffer/images.txt
find $2 -name "*jpg" -type f -exec ls {} \; | sort -V | tee -a buffer/images.txt
echo ""
files_no=`wc -l buffer/pages.txt | cut -d " " -f 1`
echo "[-]Processing $files_no files...."
count=1
while read html_file;
do
cp "$html_file" buffer/$count.html
count=`expr $count + 1`
done < "buffer/pages.txt"
while read image_file;
do
cp "$image_file" buffer/
count=`expr $count + 1`
done <"buffer/images.txt"
echo ""
cd tools/
#Get the necessary HTML files
page_files=`ls ../buffer/*.html | sort -V`
#Generate the PDFs
echo "[-]Generating shrinked PDF"
./wkhtmltopdf --page-size "A4" --title "$pdf_title" --footer-left "[doctitle]" --footer-right "[page]/[toPage]" --footer-line \
--header-center "[title]" --header-line $page_files "$pdf_name"_small.pdf
echo ""
echo "[-]Generating regular PDF"
./wkhtmltopdf --page-size "A4" --title "$pdf_title" --footer-left "[doctitle]" --footer-right "[page]/[toPage]" --footer-line \
--header-center "[title]" --header-line $page_files --disable-smart-shrinking "$pdf_name"_large.pdf
echo ""
cd ../
#Tidy up
echo "[-]Cleaning up.."
mv tools/"$pdf_name"_small.pdf tools/"$pdf_name"_large.pdf .
rm -r buffer/
fi
#++++++++++++++++++++
#Convert HTML to PNG
#+++++++++=++++++++++
if [ $1 == '-i' ] || [ $1 == '--png' ] ; then
#Call the necessary functions
logo
echo "==================="
echo " Converting to PNG "
echo "==================="
echo "[-]Enter PNG file name: (without whitespace and .png)"
read png_name
echo ""
echo "[-]Generating PNG"
./wkhtmltoimage "$2" "$png_name".png
fi