'###############################################################################
'
' Description: prn to pdf wrapper script using Ghostscript
' Version Ghostscript 8.13
'
'
' NB: You need to add a two entries to the PATH environment variable via the
' My Computer Icon
'
' They are C:\gs\gs8.13\bin & C:\gs\gs8.13\lib
'
'###############################################################################
' Constants
Const WdPrintAllDocument = 0
Const WdDoNotSaveChanges = 0
' Variables
Dim strResult, strPath, intT
' Main Code
strResult = DocToPrn ("Test.Doc", "Test.Prn")
strResult = PrnToPDF ("test.prn", "test.pdf")
WScript.Quit(0) ' Script ends here
Public Function DocToPrn( strDocFile, strPRNFile )
Dim objFSO
Dim objWord
Dim objWordDoc
Dim objWordDocs
Dim strPrevPrinter
Set objWSH = CreateObject("WSCript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
Set objWordDocs = objWord.Documents
strPath = objWSH.CurrentDirectory
bShowDebug = True
strTempFile = strPath & "\" & strPRNFile
strDocFile = objFSO.GetAbsolutePathName(strDocFile)
strFolder = objFSO.GetParentFolderName(strDocFile)
If Len(strPRNFile)=0 Then
strPRNFile = objFSO.GetBaseName(strDocFile) + ".pdf"
End If
If Len(objFSO.GetParentFolderName(strPRNFile))=0 Then
strPRNFile = sFolder + "\" + strPRNFile
End If
' Remember current active printer
strPrevPrinter = objWord.ActivePrinter
objWord.ActivePrinter = "PSPrinter" ' Name of printer for ps printed output.
' Open the Word document
Set objWordDoc = objWordDocs.Open(strDocFile)
objWord.ActiveDocument.PrintOut False , , , strTempFile , , , , , , , True
objWordDoc.Close WdDoNotSaveChanges
objWord.ActivePrinter = strPrevPrinter
objWord.Quit WdDoNotSaveChanges
Set objWord = Nothing
Set objFSO = Nothing
End Function
Public Function PrnToPDF (strFilename, strPDFFilename)
' Create a shell object
Set objWSH = CreateObject("WSCript.Shell")
strCmd = "cmd /c C:\gs\gs8.13\lib\ps2pdf " & strFilename & " " & strPDFFilename
WScript.Echo strCmd
Set objRun = objWSH.Exec(strCMD)
strCount = 0
Do While objRun.Status = 0
For intT = 1 to 50
WScript.StdOut.Write Chr(8)
Next
WScript.StdOut.Write "Create Mode: " & strPDFFilename & " = "
WScript.StdOut.Write strCount & " Cycles to create"
strCount = strCount + 1
Loop
End Function