home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/bin/bash #info screen #choose input file #specify output file name #result notification # ##----------- convert file to pdf ----------> # # author: thoughtjourney, 13/06/2005 # ##------------------------------------------> #------------------------------variables---------------------------------> INPUT="" OUTPUT="" TEMP="temp.ps" GUI=0 SUPP="The Puppy PDF Conversion Wizard (puppyPDF) takes an input file\nand converts it to PDF format. The wizard relies on 3 external programs:\n\nbash, Abiword, and ps2pdf\n\nand is recommended for use with Puppy version 1.03 or later,\nsince these are included with the standard iso.\n\n=== SUPPORTED FILE FORMATS ===\n\nAbiword Documents (.abw, .awt)\n\nMicrosoft Word Documents (.doc, .dot)\n\nRich Text Format Documents (.rtf)\n\nText Documents (.txt, .text)\n\n==============================" #-------------------------------functions--------------------------------> #---prints puppyPDF help---> function usage { echo echo -e "puppyPDF [OPTIONS... ]\n" echo -e "-i input file" echo -e "-o output file" echo -e "-h, --help prints help" echo echo -e "$SUPP" } #---gui version of events---> function gui { splash exit 0 } #---checks to ensure cli arguments are valid---> function checkArgs { if [ -f "$INPUT" ]; then #--- check to ensure file is not already pdf ---> file "$INPUT" > /tmp/type test=`grep -n PDF /tmp/type` if [ "$test" = "" ]; then rm -f /tmp/type #not a pdf file else #--- if gui is running... ---> if [ $GUI -eq 1 ]; then Xdialog --title "PDF file selected"\ --yesno "A PDF file was selected.\n\nPress YES to try again,\n\n or NO to quit\n\n" 0 0 case $? in 0) chooseFile exit 0;; 1) exit 0;; 255) echo "";; esac else #--- for cli interface ---> echo -e "\nPlease specify a valid input file\n" usage exit 0 fi fi rm -f /tmp/type else #--- input is not a file ---> if [ $GUI -eq 1 ]; then Xdialog --title "No file selected"\ --yesno "Invalid file selected.\n\nPress YES to try again,\n\n or NO to quit\n\n" 0 0 case $? in 0) chooseFile exit 0;; 1) exit 0;; 255) echo "";; esac else echo -e "\nPlease specify a valid input file\n" usage exit 0 fi fi #--- no output filename specified ---> if [ "$OUTPUT" = "" ]; then OUTPUT="$INPUT.pdf" echo -e "no output filename specified, using $INPUT.pdf\n" if [ $GUI -eq 1 ]; then Xdialog --title "INFO BOX" \ --infobox "no output filename specified,\nusing $INPUT.pdf" 13 45 20000 fi fi #--- specified output file already exists ---> if [ -f "$OUTPUT" ]; then if [ $GUI -eq 1 ]; then Xdialog --title "Filename already exists"\ --yesno "$OUTPUT already exists\n\nPress YES to overwrite,\n\nor NO to change\n\n" 0 0 case $? in 0) echo "";; 1) outputName;; 255) echo "";; esac else echo -e "$OUTPUT already exists! Press ENTER to continue or CTRL-C to quit\n" read in fi fi } #---splashscreen---> function splash { Xdialog --title "Puppy PDF Conversion Wizard"\ --help "$SUPP"\ --yesno "WELCOME to the Puppy PDF Conversion Wizard!\n\n\ Press YES to choose the file to convert,\n\n NO to exit,\n\n or HELP for more info\n\n" 0 0 case $? in 0) chooseFile;; 1) echo "" exit 1;; 255) echo "";; esac } #---choose file to convert to pdf---> function chooseFile { INPUT=`Xdialog --title "Choose File to Convert" --fselect /root/my-documents 28 60 2>&1` case $? in 0) Xdialog --title "Next step: save as..."\ --infobox "The next step is to specify the name of your pdf file.\n\n Press OK to continue.\n\n" 0 0 10000 outputName;; 1) splash;; 255) echo "";; esac } #---select output filename---> function outputName { OUTPUT=`Xdialog --title "Save As..." --fselect "$INPUT.pdf" 28 60 2>&1` case $? in 0) finalConfirm;; 1) splash;; 255) echo "";; esac } #---final confirmation---> function finalConfirm { checkArgs Xdialog --wrap --title "Confirm..."\ --yesno "The Puppy PDF Conversion Wizard \n\ will now convert\n\n$INPUT\n\nto the pdf file\n\n$OUTPUT\n\n\ If this is correct, choose YES\n To quit, choose NO\n\n" 0 0 case $? in 0) convert display;; 1) splash;; 255) echo "";; esac } #---performs the file conversion---> function convert { echo printing... #-- convert to ps---> res=`abiword --print="$TEMP" "$INPUT"` if [ "$res" = "" ]; then #-- convert to pdf---> res2=`ps2pdf "$TEMP" "$OUTPUT"` if [ "$res2" = "" ]; then #--- cleanup ---> rm -f "$TEMP" echo -e "done!\n" else echo RES2 equals $res2 echo -e "ps2pdf error! Exiting..." Xdialog --title "File Conversion error!"\ --infobox "There was an error in the file conversion process!\n\nCheck that your input file format is supported.\n\n\ Press OK to exit.\n\n" 0 0 20000 rm -f "$OUTPUT" exit 1 fi else echo RES equals $res echo -e "abiword error! Exiting..." Xdialog --title "File Conversion error!"\ --infobox "There was an error in the file conversion process!\n\nCheck that your input file format is supported.\n\n\ Press OK to exit.\n\n" 0 0 20000 rm -f "$OUTPUT" exit 1 fi } #---opens the pdf document---> function display { ghostview "$OUTPUT" & } #---commandline sequence---> function cli { checkArgs convert display } #---------------------------------main--------------------------------> if [ "$1" ]; then #cli while [ "$1" != "" ]; do case $1 in -i | -I) shift INPUT=$1 ;; -o | -O) shift OUTPUT=$1 ;; -h | --help ) usage exit ;; * ) gui exit 1 esac shift done cli else GUI=1 gui exit 0 fi exit 0 #------------------------------------------------------------------->