(view source code of wp2pdf.vbs as plain text)
Option ExplicitDim blnExitWP, colItems, strMsg, strPDFDoc, strWPDocDim objFSO, objItem, objWMIService, objWPstrMsg = ""
' Open a FileSystem ObjectSet objFSO = CreateObject( "Scripting.FileSystemObject" )
' Parse the command line argumentsWith WScript.Arguments
If .Named.Count > 0 Then Syntax
Select Case .Unnamed.Count
Case 1
strWPDoc = .Unnamed(0)
' No PDF file name specified, so we'll take the location and ' file name of the WordPerfect document and append a PDF extensionstrPDFDoc = objFSO.BuildPath( objFSO.GetParentFolderName( strWPDoc ), _
objFSO.GetBaseName( strWPDoc ) & ".pdf" )
Case 2
strWPDoc = .Unnamed(0)
strPDFDoc = .Unnamed(1)
Case Else
Syntax
End Select
End With
' Check if the WordPerfect file existsIf Not objFSO.FileExists( strWPDoc ) Then
strMsg = "ERROR: File """ & strWPDoc & """ not found" & vbCrLf & vbCrLf
Syntax
End If
' Check if WordPerfect is already active by' searching for a process named WPWIN**.EXEblnExitWP = True
Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_Process", , 48 )
For Each objItem In colItems
If Left( UCase( objItem.Name ), 5 ) = "WPWIN" And _
Right( UCase( objItem.Name ), 4 ) = ".EXE" And _
Len( objItem.Name ) < 12 Then blnExitWP = False
NextSet objWMIService = Nothing
' Create a new WP OLE Automation objectSet objWP = CreateObject( "WordPerfect.PerfectScript" )
With objWP ' Open the specified document.FileOpen( strWPDoc )
' Publish to PDF.PdfDlg( strPDFDoc )
' Close the document.Close
' Close WordPerfect unless it was already activeIf blnExitWP Then .ExitWordPerfect
End With
' Release the objectsSet objFSO = Nothing
Set objWP = Nothing
Sub Syntax( )
strMsg = strMsg & vbCrLf _
& WScript.ScriptName & ", Version 1.00" & vbCrLf _
& "Convert a WordPerfect document to Adobe PDF" & vbCrLf & vbCrLf _
& "Usage: " & UCase( WScript.ScriptName ) _
& " wpdoc_filename [ pdf_filename ]" & vbCrLf & vbCrLf _
& "Where: ""wpdoc_filename"" is the WP file to be converted" _
& vbCrLf _& " ""pdf_filename"" is the name for the PDF file" _
& vbCrLf _& " " _
& "(default is name of WP file with .PDF extension)" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit(1)
End Sub
page last modified: 2025-10-11; loaded in 0.0084 seconds