#!/bin/sh
# multiple pdfs to one pdf file
# Author: Hector Llorens
# This file is copyleft, enjoy!
szAnswer=$(zenity --entry --text "Save to:" --entry-text "output.pdf");
filesall=""
while [ $# -gt 0 ]
do
	if [ -f "$1" ];then
		files=`echo "$1" | sed 's/ /\?/g'`
		files=`echo "$files" | sed '/\.pdf$/!d'`
		filesall="$files $filesall"
	fi
	shift
done
#zenity --error --text "Error: $filesall";
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=$szAnswer -dBATCH $filesall 2> errorjpg.txt
if [ $? -ne 0 ];then errorm=`cat errorjpg.txt`;zenity --error --text "At least one file must be jpg. Error: $errorm"; fi
rm -rf errorjpg.txt


