I'm attempting to use ghostscript to set a specific page size for scanned PDF files. I can run the script when it resides in the same folder as the executable but when I move the .vbs file out of the directory I can't get it to work. The .run line is where I'm having problems. The triple quotes for exe path without arguments opens the exe but i can't figure out how to pass the parameters. I'm sure you can see that I'm pretty new to this.
strInput = InputBox ("Enter 1 for Landscape or 2 for portrait:")
Set objShell = WScript.CreateObject("WScript.Shell")
If strInput=1 then
Call LandScape
ElseIf strInput=2 Then
Call Portrait
Else
MsgBox "Your entry is invalid. Click OK to exit"
End If
Landscape sub-routine:
Sub LandScape
MsgBox "Your images are Landscape"
objShell.Run """c:\Program Files\gs\gs9.04\bin\gswin64c.exe""& "-dQUIET"&" -dNOPAUSE"&" -dBATCH"&" -dDEVICEWIDTHPOINTS=2592"&" -dDEVICEHEIGHTPOINTS=1728"&" -dFIXEDMEDIA"&" -sDEVICE=pdfwrite"&" -sOutputFile=OUTPUT.pdf"&" INPUT.pdf""
'This line works when in same directory: gswin64c -dQUIET -dNOPAUSE -dBATCH -dDEVICEWIDTHPOINTS=2592 -dDEVICEHEIGHTPOINTS=1728 -dFIXEDMEDIA -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf INPUT.pdf
End Sub
The 1st parameter to
WScript.Shell.Run()
is a full command line. So you need toCan you now deduce the correct syntax for the
objShell.Run
line?The quotes can get confusing so it sometimes helps to use
Chr(34)
instead and to keep the executable separate from its params.