(view source code of printpdf.vbs as plain text)
' Declare variables
Dim pdfKey, printCmd, printJob, strMsg
' Initialize variable
strMsg = ""
' Check command line parameters
If WScript.Arguments.Count = 0 Then Syntax
' First parameter should be a PDF file name or "/?" to request online help
If InStr( Wscript.Arguments(0), "/" ) > 0 Then Syntax
' Enable custom error handling by ErrShow subroutine
On Error Resume Next
' Read PDF print command from the registry
Set objShell = CreateObject( "WScript.Shell" )
If Err.Number Then ErrShow
pdfKey = objShell.RegRead( "HKCR\.pdf\" )
If Err.Number Then ErrShow
printCmd = objShell.RegRead( "HKCR\" & pdfKey & "\shell\print\command\" )
If Err.Number Then ErrShow
If InStr( printCmd, "{" ) Then OtherAdobe
' Execute the PDF print command for each PDF file specified
Set objArgs = WScript.Arguments
For Each strArg in objArgs
printJob = Replace( printCmd, "%1", strArg )
objShell.Run( printJob )
If Err.Number Then ErrShow
Next
' Done
WScript.Quit(0)
Sub ErrShow
strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf _
& Err.Description & vbCrLf & vbCrLf
Syntax
End Sub
Sub OtherAdobe
strMsg = vbCrLf & "This script only works when Acrobat Reader is the default association" _
& vbCrLf & "for PDF files." _
& vbCrLf & "On this PC that doesn't seem to be the case, maybe because other" _
& vbCrLf & "Adobe software is installed as well." & vbCrLf & vbCrLf
Syntax
End Sub
Sub Syntax
strMsg = strMsg & vbCrLf _
& "PrintPDF.vbs, Version 1.00" & vbCrLf _
& "Print the specified PDF file(s)." & vbCrLf & vbCrLf _
& "Usage: CSCRIPT PRINTPDF.VBS pdf_filespec" _
& vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "pdf_filespec" & Chr(34) _
& " specifies the PDF file(s) to be printed" _
& vbCrLf & vbCrLf _
& "Based on a script written by Charles Hicks, " _
& "published on the PlanetPDF Forum" & vbCrLf _
& "http://forum.planetpdf.com/webboard/wbpx.dll/~planetpdfforum" & vbCrLf _
& "Modified by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
' Abort with return code 1
WScript.Quit(1)
End Sub
page last modified: 2024-04-16; loaded in 0.0055 seconds