Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for printpdf.vbs

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

  1. ' Declare variables
  2. Dim pdfKey, printCmd, printJob, strMsg
  3.  
  4. ' Initialize variable
  5. strMsg = ""
  6.  
  7. ' Check command line parameters
  8. If WScript.Arguments.Count = 0 Then Syntax
  9. ' First parameter should be a PDF file name or "/?" to request online help
  10. If InStr( Wscript.Arguments(0), "/" ) > 0 Then Syntax
  11.  
  12. ' Enable custom error handling by ErrShow subroutine
  13. On Error Resume Next
  14.  
  15. ' Read PDF print command from the registry
  16. Set objShell = CreateObject( "WScript.Shell" )
  17. If Err.Number Then ErrShow
  18. pdfKey = objShell.RegRead( "HKCR\.pdf\" )
  19. If Err.Number Then ErrShow
  20. printCmd = objShell.RegRead( "HKCR\" & pdfKey & "\shell\print\command\" )
  21. If Err.Number Then ErrShow
  22. If InStr( printCmd, "{" ) Then OtherAdobe
  23.  
  24. ' Execute the PDF print command for each PDF file specified
  25. Set objArgs = WScript.Arguments
  26. For Each strArg in objArgs
  27. 	printJob = Replace( printCmd, "%1", strArg )
  28. 	objShell.Run( printJob )
  29. 	If Err.Number Then ErrShow
  30. Next
  31.  
  32. ' Done
  33. WScript.Quit(0)
  34.  
  35.  
  36. Sub ErrShow
  37. 	strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf _
  38. 	       & Err.Description & vbCrLf & vbCrLf
  39. 	Syntax
  40. End Sub
  41.  
  42.  
  43. Sub OtherAdobe
  44. 	strMsg = vbCrLf & "This script only works when Acrobat Reader is the default association" _
  45. 	       & vbCrLf & "for PDF files." _
  46. 	       & vbCrLf & "On this PC that doesn't seem to be the case, maybe because other" _
  47. 	       & vbCrLf & "Adobe software is installed as well." & vbCrLf & vbCrLf
  48. 	Syntax
  49. End Sub
  50.  
  51.  
  52. Sub Syntax
  53. 	strMsg = strMsg & vbCrLf _
  54. 	       & "PrintPDF.vbs,  Version 1.00" & vbCrLf _
  55. 	       & "Print the specified PDF file(s)." & vbCrLf & vbCrLf _
  56. 	       & "Usage:  CSCRIPT  PRINTPDF.VBS  pdf_filespec" _
  57. 	       & vbCrLf & vbCrLf _
  58. 	       & "Where:  " & Chr(34) & "pdf_filespec" & Chr(34) _
  59. 	       & " specifies the PDF file(s) to be printed" _
  60. 	       & vbCrLf & vbCrLf _
  61. 	       & "Based on a script written by Charles Hicks, " _
  62. 	       & "published on the PlanetPDF Forum" & vbCrLf _
  63. 	       & "http://forum.planetpdf.com/webboard/wbpx.dll/~planetpdfforum" & vbCrLf _
  64. 	       & "Modified by Rob van der Woude" & vbCrLf _
  65. 	       & "http://www.robvanderwoude.com"
  66. 	WScript.Echo strMsg
  67. 	' Abort with return code 1
  68. 	WScript.Quit(1)
  69. End Sub
  70.  

page last modified: 2024-04-16; loaded in 0.0055 seconds