Created
June 13, 2016 19:46
-
-
Save Milchreis/b2a35aa48b3aefa6179f9c302af5732a to your computer and use it in GitHub Desktop.
Concatenates different pdf files into one single file (with GUI)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ======================================================================== | |
# Author: Milchreis | |
# Description: Concatenates different pdf files into one single file with GUI | |
# Date: 2016-05-13 | |
# Dependencies: zenity, pdftk | |
# Tested and used on ubuntu and linux mint | |
# ======================================================================== | |
# Check dependencies | |
command -v zenity >/dev/null 2>&1 || { echo >&2 "Require 'zenity' package, install it please. Aborting."; exit 1; } | |
command -v pdftk >/dev/null 2>&1 || { echo >&2 "Require 'pdftk' package, install it please. Aborting."; exit 1; } | |
# Array for PDF filepaths | |
PDFS=() | |
# Inform the user | |
zenity --info --text="Choose a set of pdf-files to concatenating them." | |
# Choose a PDF file | |
FILE=`zenity --file-selection --title="Choose a pdf-file"` | |
# If a file is choosen add to array | |
if [ $? -eq 0 ] ; then | |
PDFS+=("$FILE") | |
fi | |
# Ask for more files | |
if QUESTION=$(zenity --question --text="Do you want choose next file?"); then | |
# Add and ask while the user want more | |
while $QUESTION; do | |
F=`zenity --file-selection --title="Choose a pdf-file"` | |
if [ $? -eq 0 ] ; then | |
PDFS+=($F) | |
fi | |
# If the dialog returns false break the loop | |
if ! Q=$(zenity --question --text="Do you want choose next file?"); then | |
break | |
fi | |
done | |
fi | |
# Convert the array content into a string in a single line | |
LIST=`printf '%s\n' "${PDFS[@]}"` | |
# Choose the target directory | |
OUTPUTDIR=`zenity --file-selection --directory --title="Choose the target path"` | |
# Choose a name for the target file | |
OUTPUTNAME=$(zenity --entry --title="Name for the new pdf-file" \ | |
--text="Name of the file:" \ | |
--entry-text "Output.pdf") | |
# Create the new big pdf file | |
pdftk $LIST cat output $OUTPUTDIR/$OUTPUTNAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment