/useful/trunk-1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/useful/trunk-1

« back to all changes in this revision

Viewing changes to scripts/pdf2images.sh

  • Committer: Gustav Hartvigsson
  • Date: 2024-07-10 14:19:26 UTC
  • Revision ID: git-v1:7096f7f8ddcbcd8fdf3b62130fd768b93859a627
 Added pdf2images.sh

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
 
 
3
___ARGS=$@
 
4
 
 
5
___FILE=""
 
6
___FIRST_PAGE=0
 
7
___LAST_PAGE=0
 
8
___SANITY=1
 
9
___SCALE=250
 
10
___HAS_OPTIPNG=1
 
11
 
 
12
function ___help () {
 
13
  echo "Convert a range of pages into pngs."
 
14
  echo "USAGE:"
 
15
  echo "    pdf2images.sh <file>.pdf <first page> <last page>"
 
16
  echo ""
 
17
}
 
18
 
 
19
function ___silent () {
 
20
  $@ >> /dev/null 2>&1
 
21
  return $?
 
22
}
 
23
 
 
24
function ___sanity_check () {
 
25
  # Check that we have the tools needed.
 
26
  ___silent which pdftoppm 
 
27
 
 
28
  if [ $? -gt 0 ]; then
 
29
    echo "    Can't find tool \"pdftoppm\" (Required)."
 
30
    ___SANITY=0
 
31
  fi
 
32
 
 
33
  ___silent which optipng
 
34
  if [ $? -gt 0 ]; then
 
35
    echo "    Can't find tool \"optpng\" (Not required)."
 
36
    ___HAS_OPTIPNG=0
 
37
  fi
 
38
  
 
39
  if [ $___SANITY -eq 0 ]; then
 
40
    echo "Please install the missing tools."
 
41
    echo ""
 
42
    exit 1
 
43
  fi
 
44
}
 
45
 
 
46
function ___process () {
 
47
 
 
48
  pdftoppm -f $___FIRST\
 
49
           -l $___LAST\
 
50
           -r $___SCALE\
 
51
           -gray\
 
52
           -png\
 
53
           -progress\
 
54
           $___FILE\
 
55
           ${___FILE%%.*}
 
56
 
 
57
  if [ $___HAS_OPTIPNG -eq 1 ]; then
 
58
    optipng ${___FILE%%.*}*.png
 
59
  fi
 
60
}
 
61
 
 
62
function ___parse_args () {
 
63
  if [ $# -eq 0 ]; then
 
64
    ___help
 
65
    exit 1
 
66
  fi
 
67
  
 
68
  ___FILE=$1
 
69
  shift
 
70
  ___FIRST=$1
 
71
  shift
 
72
  ___LAST=$1
 
73
  shift
 
74
 
 
75
  if [ $# -ne 0 ]; then
 
76
    echo "Nummber of arguments missmatch."
 
77
    echo ""
 
78
    ___help
 
79
    exit 1
 
80
  fi
 
81
}
 
82
 
 
83
function ___main () {
 
84
  ___sanity_check
 
85
  ___parse_args $___ARGS
 
86
  ___process
 
87
  exit 0
 
88
}
 
89
 
 
90
___main
 
91