-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpdf2image.sh
68 lines (63 loc) · 1.29 KB
/
pdf2image.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
#!/usr/bin/bash
#convert your pdf to png file
#poppler-utils or poppler needed
# Check dependencies
if ! command pdftoppm -v &> /dev/null
then
echo "poppler-utils is not instaled."
echo ""
# promt to install
echo "do you want to install(y/n):"
read -r ans
if [[ "$ans" == "y" ]]; then
if [ "$(command -v apt-get)" != "" ]; then # debian
apt-get install poppler-utils
elif [ "$(command -v pacman)" != "" ]; then # arch
pacman -S poppler
else
echo "Distro not suported"
echo "install poppler-utils yourself "
exit 127
fi
else
echo -e "Ok...\nExiting"
exit 1
fi
fi
filetoconv() {
echo -ne "Enter the pdf file name: "
read -r PDF
echo -e ""
# exit if no file detected
if ! [[ -e $(pwd)/${PDF} ]]; then
echo -e "No such file in this directory"
echo -e "Don't forget the file extension"
exit 1
fi
}
outname() {
echo -ne "Enter the output name: "
read -r NAME
echo -e ""
echo -ne "Enter the output file (png or jpeg): "
read -r EXT
echo -e ""
}
paging() {
echo -e "Select the file page to convert"
echo -e "(leave it blank to convert all pages)"
echo -ne "Enter here: "
read -r HAL
echo -e ""
if [ -z "$HAL" ]; then
PAGE=""
else
PAGE="-f ${HAL} -singlefile"
fi
}
filetoconv
paging
outname
pdftoppm "${PDF} ${NAME} -${EXT} ${PAGE}"
echo -e "Done..."
exit