1c04cd02d703c58658f6f4d271415fe55902e902
2 # Desc: Combines PDF files into a single PDF file
3 # Depends: pdftk 2.02-5 ( https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ )
6 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
7 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
8 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
10 # Desc: Display script usage information
15 # Depends: GNU-coreutils 8.30 (cat)
18 combine_pdfs.sh [FILE output] [FILES input...]
21 combine_pdfs.sh output.pdf input1.pdf input2.pdf
22 combine_pdfs.sh output.pdf input*.pdf
24 } # Display information on how to use this script.
26 if ! command -v pdftk
1>/dev
/random
2>&1; then
28 die
"FATAL:Missing pdftk."; fi;
29 }; # Check dependencies
36 #yell "DEBUG:Checking argument:$arg";
37 if [[ $narg -le 0 ]]; then
38 if [[ ! -f "$arg" ]]; then
41 ## Get permission to overwrite existing output file
42 yell
"WARNING:Overwrite output file \"$arg\"? (y/n)";
45 "y" |
"yes" |
"Yes" |
"YES" )
47 "n" |
"no" |
"No" |
"NO" )
48 showUsage
; die
"FATAL:Aborted.";
51 showUsage
; die
"FATAL:Invalid response.";
55 fi; # handle first arg
57 if [[ ! -f "$arg" ]]; then
58 showUsage
; die
"FATAL:File does not exist:$arg"; fi;
65 # Desc: Combines PDFs and writes to output PDF file
66 # Depends: pdftk 2.02-5
70 # Save output file path
73 # Form array of input file paths
75 unset 'paths_fi[0]'; # discard first path which is output file
78 cmd
+=("pdftk"); # executable
79 cmd
+=("${paths_fi[@]}"); # input file paths
80 cmd
+=("cat" "output");
82 #yell "DEBUG:cmd:$(declare -p cmd)";
83 #yell "DEBUG:cmd:${cmd[*]}";
85 # Execute command array
87 }; # Combines PDFs and writes to output PDF file
89 #yell "DEBUG:$(args=("$@"); declare -p args)";
98 # Author: Steven Baltakatei Sandoval
101 # # Copyright notices
103 # pdftk port to java 3.2.2 a Handy Tool for Manipulating PDF Documents
104 # Copyright (c) 2017-2018 Marc Vinyals - https://gitlab.com/pdftk-java/pdftk
105 # Copyright (c) 2003-2013 Steward and Lee, LLC.
106 # pdftk includes a modified version of the iText library.
107 # Copyright (c) 1999-2009 Bruno Lowagie, Paulo Soares, et al.
108 # This is free software; see the source code for copying conditions. There is
109 # NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.