See this post for latest version including screenshots
http://www.murga-linux.com/puppy/viewto ... 000#996000
/EDIT
(Screenshots at the bottom)
Updated 30 August 2008 to work with spaces in paths.
Works two ways:
1 - you call it without any input arguments, and you get a gui to specify the output file, a folder with the input files, and whether or not you want to view the file it creates.
2 - you call it from the command line with input files and/or folders, or drop things on it or use it from the rox "open with" menu or something. It will pop up a dialogue asking where you want to save it, and whether or not you want to view the file it creates (if you want to be able to use it from the console without popping up a dialogue then I'm sure you're smart enough to modify it to do that).
It will join all the .pdf files in a folder recursively, sorted in alphanumeric path order. e.g. if I do
Code: Select all
joinPdf /~/pdf
- /~/pdf/1.pdf
/~/pdf/2/4.pdf
/~/pdf/2/5/1.pdf
/~/pdf/2/5/a.pdf
/~/pdf/2/5/b.pdf
/~/pdf/2/5/c.pdf
/~/pdf/3.pdf
Code: Select all
joinpdf z b.pdf a
Requires gtkdialog3 (included in recent Puppies) and ghostscript of course.
Has no error handling to deal with ghostscript errors.
Doesn't check whether you want to overwrite if you specify an output file that already exists - just overwrites automatically.
Works recursively with pdfs in any depth of folders.
Isn't phased by folders containing files that aren't pdfs
Does make sure the output file has a .pdf extension but not a .pdf.pdf extension.
The full code at the moment:
Code: Select all
#! /bin/bash
# Script for Puppy Linux to combine pdf files.
# Version 4 by disciple, 30 August 2008.
# http://www.murga-linux.com/puppy/viewtopic.php?p=149208#149208
# Currently has NO ERROR HANDLING
# You may experience errors if you have pdfs that are broken or are not pdfs at all.
# I'm not sure, but because it doesn't delete the temporary directory at the start, you may also get unexpected results if you use "View the file afterwards", crash your Pdf viewer, and then join some more pdfs.
# Yes, the use of all those symlinks is an ugly hack, but I couldn't get gs to join files with spaces in the path otherwise :(
# Set defaults
INPUTFOLDER="`pwd`"
OUTPUTFILE="`pwd`/combined.pdf"
# Set temporary directory
TEMPFOLDER=/tmp/joinPdfdir
mkdir $TEMPFOLDER
# Initialise filecount
FILECOUNT=100
export MAIN_DIALOG="
<window title=\"Puppy's pdf joining\"icon-name=\"gtk-file\">
<vbox>
<text>
<label>You can recursively join all the pdfs in a directory and any number of subdirectories in normal alphanumeric order.</label>
</text>
<text>
<label>Make sure you name the files and folders appropriately so they are joined in the order you want.</label>
</text>
<text>
<label>e.g. Pdfs in a subfolder called "A" will come after a file called "1.pdf", and before a file called "B.pdf"</label>
</text>
<frame Location of input files>
<hbox>
<entry accept=\"directory\">
<variable>INPUTFOLDER</variable>
<input>echo '$INPUTFOLDER'</input>
</entry>
<button>
<input file stock=\"gtk-open\"></input>
<action type=\"fileselect\">INPUTFOLDER</action>
<action>refresh:INPUTFOLDER</action>
</button>
</hbox>
</frame>
<frame Output file>
<hbox>
<entry accept=\"savefilename\">
<variable>OUTPUTFILE</variable>
<input>echo '$OUTPUTFILE'</input>
</entry>
<button>
<input file stock=\"gtk-open\"></input>
<action type=\"fileselect\">OUTPUTFILE</action>
</button>
</hbox>
</frame>
<checkbox>
<label>View the file afterwards</label>
<default>true</default>
<variable>VIEWOUTPUT</variable>
</checkbox>
<hbox>
<button>
<input file stock=\"gtk-ok\"></input>
<label>Join pdfs</label>
<action type=\"exit\">JOIN-NOW</action>
</button>
<button>
<input file stock=\"gtk-dialog-info\"></input>
<label>Help</label>
<action>gtkdialog3 -c --program HELP_DIALOG</action>
</button>
<button cancel></button>
</hbox>
</vbox>
</window>"
export HELP_DIALOG="
<window title=\"joinPdf info\"icon-name=\"gtk-dialog-info\">
<vbox>
<text>
<label>If you run joinPdf from the command line with inputs, it will pop up a dialogue to ask you what you want to save the combined file as, and will then join them as you would expect. If you specify more than one input (file or folder), it will join them in the order that you specify, and things that it joins recursively are sorted globally (per input). They are deliberately not sorted folders first and then files.</label>
</text>
<text>
<label>\"\"</label>
</text>
<text>
<label>The file chooser for the output file can only choose a directory - you need to add a filename, but the script will sort out the .pdf extension.</label>
</text>
<hbox>
<button>
<label>\"Visit forum thread\"</label>
<action>defaultbrowser http://www.murga-linux.com/puppy/viewtopic.php?p=149208#149208</action>
</button>
<button ok></button>
</hbox>
</vbox>
</window>
"
export OUTPUT_FILE_DIALOG="
<window title=\"joinPdf\"icon-name=\"gtk-file\">
<vbox>
<text>
<label>What would you like to save the output file as?</label>
</text>
<hbox>
<entry accept=\"savefilename\">
<variable>OUTPUTFILE</variable>
<input>echo '$OUTPUTFILE'</input>
</entry>
<button>
<input file stock=\"gtk-open\"></input>
<action type=\"fileselect\">OUTPUTFILE</action>
</button>
</hbox>
<hbox>
<button ok>
<action type=\"exit\">JOIN-NOW</action>
</button>
<button cancel></button>
</hbox>
<checkbox>
<label>View the file afterwards</label>
<default>true</default>
<variable>VIEWOUTPUT</variable>
</checkbox>
</vbox>
</window>
"
# Show gui if run without input arguments.
test -sd "$@"
if [ "$?" = "0" ]; then
MAINGUI="`gtkdialog3 -c --program MAIN_DIALOG`"
if [ "`echo "$MAINGUI" | grep EXIT | cut -f 2 -d '\"' | sed 's/\"//g'`" != "JOIN-NOW" ]; then
exit 0
fi
INPUTFOLDER="`echo "$MAINGUI" | grep INPUTFOLDER | cut -f 2 -d '"' | sed 's/\"//g' `"
OUTPUTFILE="`echo "$MAINGUI" | grep OUTPUTFILE | cut -f 2 -d '"' | sed 's/\"//g' `"
VIEWOUTPUT="`echo "$MAINGUI" | grep VIEWOUTPUT | cut -f 2 -d '"' | sed 's/\"//g' `"
find "$INPUTFOLDER" -name '*.pdf' | sort > $TEMPFOLDER/files.txt
# Just combine the pdfs if run with input arguments.
else
# Get input filenames
for i in "$@"
do
find "$i" -name '*.pdf' | sort >> $TEMPFOLDER/files.txt
done
# Get output filename
OUTPUTFILEGUI="`gtkdialog3 --program=OUTPUT_FILE_DIALOG --center`"
OUTPUTFILE="`echo "$OUTPUTFILEGUI" | grep OUTPUTFILE | cut -f 2 -d '"' | sed 's/\"//g' `"
if [ "`echo "$OUTPUTFILEGUI" | grep EXIT | cut -f 2 -d '\"' | sed 's/\"//g'`" != "JOIN-NOW" ]; then
exit 0
fi
VIEWOUTPUT="`echo "$OUTPUTFILEGUI" | grep VIEWOUTPUT | cut -f 2 -d '"' | sed 's/\"//g' `"
fi
# Make sure output file has an extension
OUTPUTFILE="`echo $OUTPUTFILE | gawk '{gsub (/\.pdf$|\.PDF$/,"",$0); print $0'}`"
OUTPUTFILE="$OUTPUTFILE.pdf"
# Symlink files for us to join
while read line
do FILECOUNT=$(($FILECOUNT+1))
ln -s "`realpath "$line"`" $TEMPFOLDER/$FILECOUNT
done < $TEMPFOLDER/files.txt
# Remove list
rm -f $TEMPFOLDER/files.txt
# Join files together
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$OUTPUTFILE" $TEMPFOLDER/*
# View output file
if [ "$VIEWOUTPUT" = "true" ]
then
rox "$OUTPUTFILE"
fi
#remove temporary directory
rm -rf $TEMPFOLDER