[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT - stitching together 2 pdf files



On Tue, 2011-07-12 at 17:34 +0100, AG wrote:
> Hi all
> 
> Sorry for the OT, but does anyone know of a way to stitch 2 separate pdf 
> files together to make one large one?
> 
> I'm pretty sure acroread won't, but I was wondering about Xpdf or 
> possibly a command-line approach?
> 
<snip>
We made it a right click action option in Konqueror.  We put this in
${KDEDIR}/share/apps/konqueror/servicemenus/

[Desktop Action Bind_PDF]
Exec=/data/.Common/apps/PDFHandlers/bindpdf "%F"
Icon=kpdf
Name=Bind PDF file(s)

[Desktop Entry]
Actions=Bind_PDF
Encoding=UTF-8
ServiceTypes=application/pdf,application/vnd.adobe.pdf


The bindpdf scripts is as follows:

#!/bin/bash
TITLE="PDF Binder"
FILES=""
DIR="${1}"
NEWFILE=""
OFILE=""
OK=true
kdialog --title "${TITLE}" --yesno "You must select your files one at a time.\nThat is the only way I will know in which order to bind them.\nWhen you have finished selecting files, click cancel.\nI will then ask you where to save the bound file.\nShall I continue?"
if [ $? -ne 0 ];then
	exit 4
fi
while true
do
	NEWFILE="$(kdialog --title "Select PDF File to Bind" --getopenfilename "${DIR}")"
	if [ $? -ne 0 ];then
		break
	fi
	if [ ! -f "${NEWFILE}" ];then
		kdialog --title "${TITLE}" --error "The \"${NEWFILE}\" file does not exist"
		continue
	fi
	FILES="${FILES} \"${NEWFILE}\""
	DIR="${NEWFILE%/*}"
done
if [ -z "${FILES}" ];then
	kdialog --title "${TITLE}" --msgbox "No files were selected"
	exit 5
fi
while ${OK}
do
	OFILE="$(kdialog --title "Enter Bound File Name" --getsavefilename "${DIR}")"
	if [ $? -eq 0 ];then
	        EXT="${OFILE: -4:4}"
	        if [ "${EXT}" != ".pdf" -a "${EXT}" != ".PDF" ];then
	                OFILE="${OFILE}.pdf"
	        fi
	        if [ -f "${OFILE}" ];then
	                kdialog --title "${TITLE}" --warningyesno "The file ${OFILE} already exists.\nShall I overwrite it?"
	                if [ $? -ne 0 ];then
	                        continue
	                fi
		fi
		OK=false
	else
		kdialog --title "${TITLE}" --yesno "Do you really want to cancel the bind?"
		if [ $? -eq 0 ];then
			exit 6
		fi
	fi
done
FNAME="${OFILE##*/}"
DNAME="${OFILE%/*}"
kdialog --title "${TITLE}" --msgbox "PDF binding can take several minutes.\nYou will be notified via popup when the process is complete.\nThank you." &
eval pdftk ${FILES} cat output \"${HOME}/tmp/${FNAME}\"
ret=$?
if [ $ret -eq 0 ];then
        mv "${HOME}/tmp/${FNAME}" "${OFILE}"
        ret=$?
fi
if [ $ret -ne 0 ];then
        rm -f "${HOME}/tmp/${FNAME}"
        kdialog --title "${TITLE}" --error "PDF binding of ${OFILE} failed."
        exit 5
fi
kdialog --title "${TITLE}" --msgbox "PDF Binding Completed for:\n${OFILE}"


In case anyone is interested, we did the same thing for reducing PDF
file size - make it right click option on a file:

#!/bin/bash
OFILE=""
OK=true
FILES="\"$(echo "${1}" | sed 's/ \//\" \"\//g')\""
DIR="$(echo ${FILES} | sed 's/\"\([^\"]*\)\".*/\1/')"
DIR="${DIR%/*}/"
EXT=""
ret=0
while ${OK}
do
	OFILE="$(kdialog --title "Enter New Reduced PDF File Name" --getsavefilename "${DIR}")"
	if [ $? -ne 0 ];then
		exit 4
	fi
	EXT="${OFILE: -4:4}"
	if [ "${EXT}" != ".pdf" -a "${EXT}" != ".PDF" ];then
		OFILE="${OFILE}.pdf"
	fi
	if [ -f "${OFILE}" ];then
		kdialog --title "Reduce PDF File" --warningyesno "The file ${OFILE} already exists.\nShall I overwrite it?"
		if [ $? -ne 0 ];then
			continue
		fi
	fi
	OK=false
done
FNAME="${OFILE##*/}"
DNAME="${OFILE%/*}"
kdialog --title "Reduce PDF File" --msgbox "PDF reduction can take several minutes.\nYou will be notified via popup when the process is complete.\nThank you." &
eval gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=\"${HOME}/tmp/${FNAME}\" ${FILES}
ret=$?
if [ $ret -eq 0 ];then
	mv "${HOME}/tmp/${FNAME}" "${OFILE}"
	ret=$?
fi
if [ $ret -ne 0 ];then
	rm -f "${HOME}/tmp/${FNAME}"
	kdialog --title "Reduce PDF File" --error "PDF Reduction of ${OFILE} failed."
	exit 5
fi
kdialog --title "Reduce PDF File" --msgbox "PDF Reduction Completed for:\n${OFILE}"





Reply to: