Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for printpdf.rex

(view source code of printpdf.rex as plain text)

  1. /* Check and parse command line arguments */
  2. Parse Upper Arg pdflist
  3. If pdflist = "" Then Call Syntax
  4. If Pos( "/", pdflist ) > 0 Then Call Syntax
  5. pdflist = Strip( Translate( pdflist, " ", "," ) )
  6.  
  7. /* Initialize RexxUtil */
  8. Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  9. Call sysloadfuncs
  10.  
  11. /* Check if the specified files exist and build a file list */
  12. pdf.  = ""
  13. pdf.0 = 0
  14. Do Until pdflist = ""
  15. 	If Left( pdflist, 1 ) = '"' Then Do
  16. 		Parse Value pdflist With '"'nextspec'"'pdflist
  17. 		pdflist = Strip( pdflist )
  18. 	End
  19. 	Else Do
  20. 		Parse Value pdflist With nextspec pdflist
  21. 	End
  22. 	Call SysFileTree nextspec, "files.", "FO"
  23. 	If files.0 > 0 Then Do i = 1 To files.0
  24. 		j     = pdf.0 + 1
  25. 		pdf.j = files.i
  26. 		pdf.0 = j
  27. 	End
  28. 	Else Do
  29. 		Call Syntax
  30. 	End
  31. End
  32.  
  33. /* Reformat the file list */
  34. Do i = 1 To pdf.0
  35. 	pdflist = pdflist||' "'||pdf.i||'"'
  36. End
  37.  
  38. /* Initialize W32Funcs */
  39. Call RxFuncAdd "w32loadfuncs", "W32Util", "w32loadfuncs"
  40. Call w32loadfuncs
  41.  
  42. /* Read default PDF print command from registry */
  43. handle   = w32RegOpenKey( "HKEY_CLASSES_ROOT", ".pdf" )
  44. filetype = w32RegQueryValue( handle, "" )
  45. Call w32RegCloseKey handle
  46. handle   = w32RegOpenKey( "HKEY_CLASSES_ROOT", filetype||"\shell\print\command" )
  47. printcmd = w32RegQueryValue( handle, "" )
  48. Call w32RegCloseKey handle
  49.  
  50. /* Check if no other (Adobe) software is used in the print command */
  51. If Pos( "{", printcmd ) > 0 Then Do
  52. 	Say
  53. 	Say "This script will only work if Acrobat Reader is the default association"
  54. 	Say "for PDF files."
  55. 	Say "On this computer, that doesn't seem to be the case, possibly because"
  56. 	Say "other Adobe software is installed."
  57. 	Call Syntax
  58. End
  59.  
  60. /* Display a message telling the user to manually close Acrobat Reader */
  61. Say
  62. Say "Waiting for you to close the Acrobat Reader window manually after it has sent"
  63. Say "all files to the printer..."
  64.  
  65. /* Execute the print command for every file from the list */
  66. Parse Value printcmd With printcmd'"%1"'printtail
  67. printcmd = printcmd||pdflist||printtail
  68. address SYSTEM '"'||printcmd||'"'
  69.  
  70. /* Normal program termination */
  71. Exit 0
  72.  
  73.  
  74. Syntax:
  75. 	Say
  76. 	Say "PrintPDF.rex,  Version 1.00"
  77. 	Say "Print a (list of) specified PDF file(s)"
  78. 	Say
  79. 	Say "Usage:   <REXX>   PRINTPDF.REX   pdflist"
  80. 	Say
  81. 	say 'Where:  "<REXX>"  is your Rexx interpreter:'
  82. 	say "                  - Windows: REGINA.EXE (with RexxUtil installed)"
  83. 	say "                  - OS/2:    no need to specify, just rename script to *.cmd"
  84. 	Say '        "pdflist" specifies the file(s) to be printed; list format can'
  85. 	Say "                  be wildcards, or space separated, or any combination"
  86. 	Say
  87. 	Say "Arguments should be enclosed in double quotes if they contain spaces"
  88. 	Say
  89. 	Say "Written by Rob van der Woude"
  90. 	Say "http://www.robvanderwoude.com"
  91. 	Exit 1
  92. Return
  93.  

page last uploaded: 2017-04-06, 13:33