' gxps.vbs WindowsScript wrapper v0.1, 12/08/15
'
'
' *Purpose*
' Use this WindowsScript to convert XPSs using drag&drop:
' 0. make sure you have windows script host v5.1 on your system
' (enter 'cscript' in a DOS-Box and compare version number)
' 1. adjust the path settings below to fit your needs
' 2a. put this file somewhere on the desktop
' 2b. start->execute, enter "sendto", drag the script or a link to it in
' sendto window (adjust names and icon as you like)
' 3a. drag one or more xps-files on the icon and they will be converted.
' 3b. select xps-file(s) and send it via the send-to menu to gsxps!
'
' You may wish to create copies of this file with different options set.
'
'
' *History*
' V0.1 initial release
' *** change path to your needs ***
path = "<LOCATION>\" '!!! must end with a backslash !!!
gxps = "gxpswin32-9.18.exe"
' *** change default options to your needs ***
opts = "-sDEVICE=pdfwrite -dNOPAUSE -sPDFSETTINGS=/prepress"
' no changes needed below this line
' ##########################################################################
Dim wsh, args, infile, fs
title="XPS to PDF Script"
' get input files
Set wsh = WScript.CreateObject("WScript.Shell")
Set args = WScript.Arguments
If args.Count = 0 Then
MsgBox "XPS to PDF converter frontend script." & vbCR & _
"Please use drag & drop to specify input files.", vbInformation, title
WScript.Quit
End If
' check path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(path & gxps) Then
MsgBox "Could not find GXPS!" & vbCR & "(looked for '" & path & gxps & "')", vbCritical, title
WScript.Quit
End If
'process files
For i = 0 To args.Count-1
infile = args(i)
' check input file
If fso.FolderExists(infile) Then
MsgBox "'" & infile & "' is a folder!" & vbCR & _
title & " only handles proper files.", vbInformation, title
Else
If Not fso.FileExists(infile) Then
MsgBox "Error opening input-file" & vbCR & "'" & infile & "'", vbCritical , title
Else
' run gxps
If(LCase(getExtension(infile))="xps") Then 'decode
ret = wsh.Run(Chr(34) & path & gxps & Chr(34) & Chr(32) & " -sOutputFile=" & Chr(34) & _
getBasename(infile) & ".pdf" & Chr(34) & Chr(32) & opts & Chr(32) & Chr(34) & _
getBasename(infile) & ".xps" & Chr(34), 1, True)
End If
' diagnostics
Select Case ret
Case (0) 'okeydokey
Case (-1)
MsgBox "GXPS aborted by user!", vbExclamation, title
Case (1)
MsgBox "Error returned by GXPS!" & vbCR & "(Check GXPS options and input file formats.)" & vbCR & "Used Options: " & opts, vbCritical, title
Case Else
MsgBox "Received unknown GXPS return-code: " & ret, vbCritical, title
End Select
End If
End If
Next
WScript.Quit
' *******************************************************************
' utility functions
Function getBasename(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
getBasename = f.ParentFolder & "\" & fso.GetBaseName(filespec)
End Function
Function getExtension(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
getExtension = fso.GetExtensionName(filespec)
End Function
' *******************************************************************
'eof