-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf_1_to_all.sh
executable file
·100 lines (68 loc) · 2.42 KB
/
pdf_1_to_all.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
#!/bin/bash
#
# blabla
# Patrick CAO HUU THIEN <[email protected]>
#
readonly VERSION=1
# History
# * 06 Feb 2013 - 1
# - initial version
function usage() {
cat <<EOT
Usage: $(basename $0) [-hnvVdn] <final PDF file> <PDF file1> <PDF file2> ...
Get the first page of each PDF file and concat to a new one
Options:
-h : print this page
-V : print version
-v : verbose -- conflict with -q
-q : quiet -- conflict with -v
-n : test mode ; do not write on disk
EOT
}
## Functions ##############################################
function do_debug () { [ $DEBUG ] && echo "[debug] $@" >&2 || false; }
#do_debug bla bla in debug
#do_debug mode debug || echo mode not debug
function do_crit () { cal=`caller 0`;echo "E: (line: $cal) $@" >&2; exit 1; }
#do_crit This is an critical error
function do_err () { echo "E: $@" >&2; exit 1; }
#do_err This is an error test
function do_err_usage () { echo "E: $@" >&2; usage; exit 1; }
#do_err_usage This is an error with usage
function do_warn () { echo "W: $@"; }
#do_warn This is an error test
function do_print () { [ -z $QUIET ] && echo "$@"; }
#do_print this is a test
function do_printf () { [ -z $QUIET ] && printf "$@"; }
#do_printf "%10s_%20s_%-10s_%s\n" this is a test
function do_verbose () { [ -n "$VERBOSE" ] && echo "$@"; }
function do_test () { [ -n "$TEST" ] && { [ -n "$*" ] && echo "[test] $@" || true; } || false; }
#do_test echo test || echo mode production
#do_test || echo mode production2
function do_trap_user() { echo "Interuption by user"; }
function do_trap_exit() { echo "exit prout"; }
## Arguments ##############################################
OPTIND=1
while getopts hnvVdq opt ; do
case "$opt" in
h) usage; exit;;
v) VERBOSE=1;;
d) DEBUG=1;;
q) QUIET=1;;
n) TEST=1;;
V) echo "$(basename $0) - $VERSION"; exit;;
esac
done
shift $(($OPTIND - 1))
test $# -gt 1 || do_err_usage Missing argument
FILEOUT="$1"
test -n "$FILEOUT" || do_err_usage Argument 1 must be NON EMPTY
test -f $FILEOUT && do_err "File $FILEOUT already exists. Abort"
shift
# warning: use "$@" to preserve spaces in file names
#for f in "$@"; do echo "|$f|"; done
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=1 -dLastPage=1 -sOutputFile="$FILEOUT" "$@"
# Main ####################################################
#trap do_trap_user TERM INT
#trap do_trap_exit EXIT
# vim:set ts=4 sw=4 sta ai spelllang=en: