option explicit Dim objwsh, AgrObj, strOutPath,objFso Dim strSourceName, strDestName, strPDFShellCmd,strSourcePath Set objFso = CreateObject("Scripting.FileSystemObject") Set objwsh = WScript.CreateObject("WScript.Shell") Set AgrObj = WScript.Arguments If AgrObj.count <> 0 Then strSourcePath = AgrObj(0) else wscript.Quit End If strOutPath = "C:\PDFPrint\PSInvoiceFiles\" 'set the name of the output file, and the GS command to run that will create the file strDestName = strOutPath & Replace(DocTitle(), " ", "_") & "-" & stamp() & ".pdf" strPDFShellCmd = chr(34) & "C:\Program Files\gs\gs8.61\lib\ps2pdf.bat " & chr(34) & strSourcePath & " " & strDestName 'check for a duplicate file name before running the command if objFso.FileExists(strDestName) then objFso.DeleteFile strDestName end if 'run the gs command on the file objwsh.Run ("ps2pdf.bat " & strSourcePath & " " & strDestName) '******************************************************************************************************** 'Function to get the document name out of the postscript Function DocTitle() Dim f, ts, StrLine,objFso set objFso = WScript.CreateObject("Scripting.FileSystemObject") set f = objFSO.GetFile(strSourcePath) If Not objFSO.FileExists(strSourcePath) Then msgbox "An error has occured" & vbcrlf & "temp file does not exist" & vbcrlf & "contact I.T on 2345" WScript.Quit End If set ts = f.OpenAsTextStream(1) Do While Not ts.AtEndOfStream StrLine = ts.ReadLine() If InStr(strLine, "%%Title") Then StrLine = replace(strLine,"%%Title: ","") StrLine = replace(strLine,".","-") StrLine = replace(strLine,"\","-") StrLine = replace(strLine,"/","-") StrLine = replace(strLine,":","-") StrLine = replace(strLine,"*","-") StrLine = replace(strLine,"?","-") StrLine = replace(strLine,chr(34),"-") StrLine = replace(strLine,"<","-") StrLine = replace(strLine,">","-") StrLine = replace(strLine,"|","-") StrLine = replace(strLine,"_","-") exit Do Else strLine = "no-title" End If Loop ts.close() set f = Nothing DocTitle = strLine End Function Function stamp() Rnd(-1) Randomize(Timer()) stamp = round((rnd() * 1000)) If len(stamp) = 1 Then stamp = "00" & stamp End If If len(stamp) = 2 Then stamp = "0" & stamp End If End Function