Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wp2pdf.vbs

(view source code of wp2pdf.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim blnExitWP, colItems, strMsg, strPDFDoc, strWPDoc
  4. Dim objFSO, objItem, objWMIService, objWP
  5.  
  6. strMsg = ""
  7.  
  8. ' Open a FileSystem Object
  9. Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  10.  
  11. ' Parse the command line arguments
  12. With WScript.Arguments
  13. 	If .Named.Count > 0 Then Syntax
  14. 	Select Case .Unnamed.Count
  15. 		Case 1
  16. 			strWPDoc  = .Unnamed(0)
  17. 			' No PDF file name specified, so we'll take the location and
  18. 			' file name of the WordPerfect document and append a PDF extension
  19. 			strPDFDoc = objFSO.BuildPath( objFSO.GetParentFolderName( strWPDoc ), _
  20. 			                              objFSO.GetBaseName( strWPDoc ) & ".pdf" )
  21. 		Case 2
  22. 			strWPDoc  = .Unnamed(0)
  23. 			strPDFDoc = .Unnamed(1)
  24. 		Case Else
  25. 			Syntax
  26. 	End Select
  27. End With
  28.  
  29. ' Check if the WordPerfect file exists
  30. If Not objFSO.FileExists( strWPDoc ) Then
  31. 	strMsg = "ERROR:  File """ & strWPDoc & """ not found" & vbCrLf & vbCrLf
  32. 	Syntax
  33. End If
  34.  
  35. ' Check if WordPerfect is already active by
  36. ' searching for a process named WPWIN**.EXE
  37. blnExitWP = True
  38. Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  39. Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_Process", , 48 )
  40. For Each objItem In colItems
  41. 	If Left( UCase( objItem.Name ), 5 ) = "WPWIN" And _
  42. 	   Right( UCase( objItem.Name ), 4 ) = ".EXE" And _
  43. 	   Len( objItem.Name ) < 12 Then blnExitWP = False
  44. Next
  45. Set objWMIService = Nothing
  46.  
  47. ' Create a new WP OLE Automation object
  48. Set objWP = CreateObject( "WordPerfect.PerfectScript" )
  49.  
  50. With objWP
  51. 	' Open the specified document
  52. 	.FileOpen( strWPDoc )
  53.  
  54. 	' Publish to PDF
  55. 	.PdfDlg( strPDFDoc )
  56.  
  57. 	' Close the document
  58. 	.Close
  59.  
  60. 	' Close WordPerfect unless it was already active
  61. 	If blnExitWP Then .ExitWordPerfect
  62. End With
  63.  
  64. ' Release the objects
  65. Set objFSO = Nothing
  66. Set objWP  = Nothing
  67.  
  68.  
  69. Sub Syntax( )
  70. 	strMsg = strMsg & vbCrLf _
  71. 	       & WScript.ScriptName & ",  Version 1.00" & vbCrLf _
  72. 	       & "Convert a WordPerfect document to Adobe PDF" & vbCrLf & vbCrLf _
  73. 	       & "Usage:  " & UCase( WScript.ScriptName ) _
  74. 	       & "  wpdoc_filename  [ pdf_filename ]" & vbCrLf & vbCrLf _
  75. 	       & "Where:  ""wpdoc_filename""  is the WP file to be converted" _
  76. 	       & vbCrLf _
  77. 	       & "        ""pdf_filename""    is the name for the PDF file" _
  78. 	       & vbCrLf _
  79. 	       & "                          " _
  80. 	       & "(default is name of WP file with .PDF extension)" _
  81. 	       & vbCrLf & vbCrLf _
  82. 	       & "Written by Rob van der Woude" & vbCrLf _
  83. 	       & "http://www.robvanderwoude.com"
  84. 	WScript.Echo strMsg
  85. 	WScript.Quit(1)
  86. End Sub
  87.  

page last modified: 2024-04-16; loaded in 0.0109 seconds