home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 11 / AACD11.ISO / AACD / Utilities / PS2PDF / ps2pdf next >
Text File  |  1999-10-02  |  4KB  |  133 lines

  1. /*
  2. Convert PostScript files to Portable Document Format using GhostScript
  3. $VER: ps2pdf 1.0 (21.9.99) by Neil Bothwick
  4. */
  5.  
  6. /* ;;; Initialise */
  7. call addlib('rexxsupport.library',0,-30,0)
  8. options results
  9. signal on error
  10. VerStr = sourceline(3)
  11. VerStr = subword(VerStr,2,words(VerStr) - 4)
  12. WinTitle = 'Convert Postscript to PDF'
  13. GuiPort = 'PS2PDF'
  14. PrgPort = GuiPort'.1'
  15.  
  16. MUIA_Menuitem_Shortcut              = 0x80422030
  17. MUIM_Application_AboutMUI           = 0x8042d21d
  18. MUIM_Application_OpenConfigWindow   = 0x804299ba
  19. MUIA_Group_SameHeight               = 0x8042037e
  20. MUIA_Group_SameWidth                = 0x8042b3ec
  21. MUIA_Group_Spacing                  = 0x8042866d
  22. MUIA_Group_Columns                  = 0x8042f416
  23. MUIA_Group_Rows                     = 0x8042b68f
  24. MUIA_Selected                       = 0x8042654b
  25. MUIA_Disabled                       = 0x80423661
  26. MUIA_Application_Author             = 0x80424842
  27. MUIA_Application_Copyright          = 0x8042ef4d
  28. MUIA_Application_Description        = 0x80421fc6
  29. MUIA_Application_Title              = 0x804281b8
  30. MUIA_Application_Version            = 0x8042b33f
  31. MUIA_Application_Sleep              = 0x80425711
  32.  
  33. ;;;
  34. /* ;;; Create main window */
  35. thisport = openport(PrgPort)
  36. if thisport = 0 then exit
  37. address(GuiPort)
  38. window id MAIN port PrgPort command 'QUIT' title '"'WinTitle'"'
  39.     menu ID PROJM label 'Project'
  40.         item ID ABOUM port PrgPort command '"ABOUT"' ATTRS MUIA_Menuitem_Shortcut '"?"' label 'About'
  41.         item  port GuiPort command '"method 'MUIM_Application_AboutMUI' 0"' label 'About MUI'
  42.         menu ID SETTM label 'Settings'
  43.             item port PrgPort command '"method 'MUIM_Application_OpenConfigWindow'"' label 'MUI...'
  44.             endmenu
  45.         item ID QUITM port PrgPort command 'QUIT' ATTRS MUIA_Menuitem_Shortcut 'Q' label 'Quit'
  46.         endmenu
  47.  
  48.     group ATTRS MUIA_Group_Columns 2
  49.         label DOUBLE LEFT 'Input file'
  50.             popasl ID INF port PrgPort help '"The postscript file to convert"'
  51.         label DOUBLE LEFT 'Output file'
  52.             popasl ID OUTF port PrgPort help '"The PDF file you wish to create"'
  53.         space
  54.         endgroup
  55.  
  56.     group HORIZ
  57.         button ID CONV port PrgPort command '"Convert"' help '"Start the conversion"' label 'Convert'
  58.         endgroup
  59.     endwindow
  60. ;;;
  61. /* ;;; Check that GhostScript is installed correctly */
  62. signal off error
  63. address command 'Assign >NIL: GhostScript: EXISTS'
  64. signal on error
  65. if RC > 0 then do
  66.     call ShowMsg('You must install GhostScript first')
  67.     call Quit()
  68.     end
  69. ;;;
  70. /* ;;; Main loop */
  71. do forever
  72.     call waitpkt(PrgPort)
  73.     packet = getpkt(PrgPort)
  74.     if packet = '0000 0000'x then iterate
  75.     cmd = getarg(packet)
  76.     call reply(packet,0)
  77.     parse var cmd cmd args
  78.     interpret 'call 'cmd'("'args'")'
  79.     end
  80. ;;;
  81. /* ;;; Do the conversion */
  82. Convert:
  83.     'popasl ID INF'
  84.     InFile = result
  85.     if InFile = '' then do
  86.         call ShowMsg('You must supply the name of a file to convert')
  87.         return
  88.         end
  89.     'popasl ID OUTF'
  90.     OutFile = result
  91.     if OutFile = '' then OutFile = InFile'.pdf'
  92.     InDir = left(InFile,max(lastpos('/',InFile),lastpos(':',InFile)))
  93.     call Pragma('D',InDir)
  94.     'application' MUIA_Application_Sleep TRUE
  95.     address command 'GhostScript:gs >T:ps2pdf.tmp -q -dNOPAUSE -dBATCH -sPAPERSIZE=a4 -sDEVICE=pdfwrite -sOutputFile='OutFile InFile
  96.     'application' MUIA_Application_Sleep FALSE
  97.     if word(statef('T:ps2pdf.tmp'),2) = 0 then call ShowMsg('Conversion successful')
  98.     else do
  99.         call ShowMsg('Conversion failed')
  100.         address command 'AACDfile T:pdf2ps.tmp'
  101.         end
  102.     options failat 21
  103.     call delete('T:pdf2ps.tmp')
  104.     call Quit()
  105.     return
  106. ;;;
  107. /* ;;; Show about requester */
  108. About:
  109.     call ShowMsg(VerStr' by Neil Bothwick\n\nConvert Postscript files to PDF using GhostScript\n\n© 1999 by KornyBoth Productions Inc.\nThis product is Shareware\nShareware fee B&H20')
  110.     return
  111. ;;;
  112. /* ;;; ShowMsg */
  113. ShowMsg:
  114.     parse arg msg
  115.     'request id MAIN title "'WinTitle'" gadgets "OK" string' msg
  116.     return
  117. ;;;
  118. /* ;;; Error handler */
  119. Error:
  120.     address command 'requestchoice >NIL: "error" "Error' RC 'in line' sigl'" "OK"'
  121.     if RC = 5 then return
  122.     call ShowMsg('Error' RC 'in line' sigl)
  123.     call Quit()
  124.     return
  125. ;;;
  126. /* ;;; Quit */
  127. Quit:
  128.     address(GuiPort)
  129.     'QUIT'
  130.     exit
  131. ;;;
  132.  
  133.