puppypdf 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #!/bin/bash
  2. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  3. #v426 nikin: bugfix.
  4. #120202 rodin.s: internationalized.
  5. #120329 Xdialog bug --yesno supposed to "yes" "No" buttons, but they are "OK" "Cancel".
  6. export TEXTDOMAIN=puppypdf
  7. export TEXTDOMAINDIR=/usr/share/locale
  8. export OUTPUT_CHARSET=UTF-8
  9. eval_gettext () {
  10. local myMESSAGE=$(gettext "$1")
  11. eval echo \"$myMESSAGE\"
  12. }
  13. Yes_lbl="$(gettext 'YES')"
  14. No_lbl="$(gettext 'NO')"
  15. #info screen
  16. #choose input file
  17. #specify output file name
  18. #result notification
  19. #
  20. ##----------- convert file to pdf ---------->
  21. #
  22. # author: thoughtjourney, 13/06/2005
  23. #
  24. ##------------------------------------------>
  25. #------------------------------variables--------------------------------->
  26. INPUT=""
  27. OUTPUT=""
  28. TEMP="temp.ps"
  29. GUI=0
  30. SUPP="$(gettext '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=============================="
  31. #-------------------------------functions-------------------------------->
  32. #---prints puppyPDF help--->
  33. function usage
  34. {
  35. echo
  36. echo -e "puppyPDF [OPTIONS... ]\n"
  37. echo -e "-i $(gettext 'input file')"
  38. echo -e "-o $(gettext 'output file')"
  39. echo -e "-h, --help $(gettext 'prints help')"
  40. echo
  41. echo -e "$SUPP"
  42. }
  43. #---gui version of events--->
  44. function gui
  45. {
  46. splash
  47. exit 0
  48. }
  49. #---checks to ensure cli arguments are valid--->
  50. function checkArgs
  51. {
  52. if [ -f "$INPUT" ]; then
  53. #--- check to ensure file is not already pdf --->
  54. file "$INPUT" > /tmp/type
  55. test=`grep -n PDF /tmp/type`
  56. if [ "$test" = "" ]; then
  57. rm -f /tmp/type #not a pdf file
  58. else
  59. #--- if gui is running... --->
  60. if [ $GUI -eq 1 ]; then
  61. Xdialog --title "$(gettext 'PDF file selected')" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$(gettext 'A PDF file was selected.\n\nPress YES to try again,\n\n or NO to quit')\n\n" 0 0
  62. case $? in
  63. 0)
  64. chooseFile
  65. exit 0;;
  66. 1)
  67. exit 0;;
  68. 255)
  69. echo "";;
  70. esac
  71. else
  72. #--- for cli interface --->
  73. echo -e "\n$(gettext 'Please specify a valid input file')\n"
  74. usage
  75. exit 0
  76. fi
  77. fi
  78. rm -f /tmp/type
  79. else
  80. #--- input is not a file --->
  81. if [ $GUI -eq 1 ]; then
  82. Xdialog --title "$(gettext 'No file selected')" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$(gettext 'Invalid file selected.\n\nPress YES to try again,\n\n or NO to quit')\n\n" 0 0
  83. case $? in
  84. 0)
  85. chooseFile
  86. exit 0;;
  87. 1)
  88. exit 0;;
  89. 255)
  90. echo "";;
  91. esac
  92. else
  93. echo -e "\n$(gettext 'Please specify a valid input file')\n"
  94. usage
  95. exit 0
  96. fi
  97. fi
  98. #--- no output filename specified --->
  99. if [ "$OUTPUT" = "" ]; then
  100. OUTPUT="$INPUT.pdf"
  101. echo -e "$(gettext 'no output filename specified, using') $INPUT.pdf\n"
  102. if [ $GUI -eq 1 ]; then
  103. Xdialog --title "INFO BOX" \
  104. --infobox "$(gettext 'no output filename specified,\nusing') $INPUT.pdf" 13 45 20000
  105. fi
  106. fi
  107. #--- specified output file already exists --->
  108. if [ -f "$OUTPUT" ]; then
  109. if [ $GUI -eq 1 ]; then
  110. Xdialog --title "$(gettext 'Filename already exists')" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$OUTPUT $(gettext 'already exists\n\nPress YES to overwrite,\n\nor NO to change')\n\n" 0 0
  111. case $? in
  112. 0)
  113. echo "";;
  114. 1)
  115. outputName;;
  116. 255)
  117. echo "";;
  118. esac
  119. else
  120. echo -e "$OUTPUT $(gettext 'already exists! Press ENTER to continue or CTRL-C to quit')\n"
  121. read in
  122. fi
  123. fi
  124. }
  125. #---splashscreen--->
  126. function splash
  127. {
  128. Xdialog --title "$(gettext 'Puppy PDF Conversion Wizard')" --help "$SUPP" --ok-label "$Yes_lbl" --cancel-label "$No_lbl"\
  129. --yesno "$(gettext 'WELCOME to the Puppy PDF Conversion Wizard!')\n\n\
  130. $(gettext 'Press YES to choose the file to convert,\n\n NO to exit,\n\n or HELP for more info')\n\n" 0 0
  131. case $? in
  132. 0)
  133. chooseFile;;
  134. 1)
  135. echo ""
  136. exit 1;;
  137. 255)
  138. echo "";;
  139. esac
  140. }
  141. #---choose file to convert to pdf--->
  142. function chooseFile
  143. {
  144. #Fixed so that the program doesnt crashon GTK error messages apperaring changed /root to ~ for compatibility reasons
  145. INPUT=`Xdialog --stdout --title "Choose File to Convert" --fselect ~ 28 60 2>/dev/null`
  146. case $? in
  147. 0)
  148. Xdialog --title "$(gettext 'Next step: save as...')"\
  149. --infobox "$(gettext 'The next step is to specify the name of your pdf file.\n\n Press OK to continue.')\n\n" 0 0 10000
  150. outputName;;
  151. 1)
  152. splash;;
  153. 255)
  154. echo "";;
  155. esac
  156. }
  157. #---select output filename--->
  158. function outputName
  159. {
  160. OUTPUT=`Xdialog --stdout --title "Save As..." --fselect "$INPUT.pdf" 28 60 2>/dev/null`
  161. case $? in
  162. 0)
  163. finalConfirm;;
  164. 1)
  165. splash;;
  166. 255)
  167. echo "";;
  168. esac
  169. }
  170. #---final confirmation--->
  171. function finalConfirm
  172. {
  173. checkArgs
  174. Xdialog --wrap --title "$(gettext 'Confirm...')" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" \
  175. --yesno "$(gettext 'The Puppy PDF Conversion Wizard') \n\
  176. `eval_gettext \"will now convert\n\n\\\$INPUT\n\nto the pdf file\"`\n\n$OUTPUT\n\n\
  177. $(gettext 'If this is correct, choose YES\n To quit, choose NO')\n\n" 0 0
  178. case $? in
  179. 0)
  180. convert
  181. display;;
  182. 1)
  183. splash;;
  184. 255)
  185. echo "";;
  186. esac
  187. }
  188. #---performs the file conversion--->
  189. function convert
  190. {
  191. echo printing...
  192. #-- convert to ps--->
  193. res=`abiword --to=ps --to-name="$TEMP" "$INPUT"`
  194. if [ "$res" = "" ]; then
  195. #-- convert to pdf--->
  196. res2=`ps2pdf "$TEMP" "$OUTPUT"`
  197. if [ "$res2" = "" ]; then
  198. #--- cleanup --->
  199. rm -f "$TEMP"
  200. echo -e "done!\n"
  201. else
  202. echo RES2 equals $res2
  203. echo -e "$(gettext 'ps2pdf error! Exiting...')"
  204. Xdialog --title "$(gettext 'File Conversion error!')"\
  205. --infobox "$(gettext 'There was an error in the file conversion process!\n\nCheck that your input file format is supported.\n\n\
  206. Press OK to exit').\n\n" 0 0 20000
  207. rm -f "$OUTPUT"
  208. exit 1
  209. fi
  210. else
  211. echo RES equals $res
  212. echo -e "$(gettext 'abiword error! Exiting...')"
  213. Xdialog --title "$(gettext 'File Conversion error!')"\
  214. --infobox "$(gettext 'There was an error in the file conversion process!\n\nCheck that your input file format is supported.\n\n\
  215. Press OK to exit').\n\n" 0 0 20000
  216. rm -f "$OUTPUT"
  217. exit 1
  218. fi
  219. }
  220. #---opens the pdf document--->
  221. function display
  222. {
  223. ghostview "$OUTPUT" &
  224. }
  225. #---commandline sequence--->
  226. function cli
  227. {
  228. checkArgs
  229. convert
  230. display
  231. }
  232. #---------------------------------main-------------------------------->
  233. if [ "$1" ]; then
  234. #cli
  235. while [ "$1" != "" ]; do
  236. case $1 in
  237. -i | -I) shift
  238. INPUT=$1
  239. ;;
  240. -o | -O) shift
  241. OUTPUT=$1
  242. ;;
  243. -h | --help ) usage
  244. exit
  245. ;;
  246. * ) gui
  247. exit 1
  248. esac
  249. shift
  250. done
  251. cli
  252. else
  253. GUI=1
  254. gui
  255. exit 0
  256. fi
  257. exit 0
  258. #------------------------------------------------------------------->