How can I use a script to export my MapViewer map to a vector PDF file using Open Office?

This article contains a sample script for creating a vector PDF file using OpenOffice application.

To run this script:

  1. Copy the script below, or click here to download the BAS file: Export_Plot_to_OpenOfficePDF.bas.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.


' Export_Plot_to_OpenOfficePDF.bas
' Copyright (C) Golden Software Inc. 1992-2015
' Uses the OpenOffice To create a vector PDF.
' This script requires that you have OpenOffice.
' It is available for free from
' This has been tested with MapViewer 8 and OpenOffice 4.1.1.
' ***To use this script:***
' Have MapViewer running with the map you want to export loaded
' as the active document, then run this script from within Scripter.

Sub Main
  Dim oServiceManager As Object
  Dim oDesktop As Object
  Dim oDocument As Object
  Dim oDispatcher As Object
  Dim strFile, strURL, strDir, strName, strFull As String
  Dim mvApp, plot As Object
  Dim i,j,ln As Integer

  ' Start the OOo ServiceManager.
  ' Issue an error message and quit if it fails.
  On Error GoTo NeedOOo
  Set oServiceManager= CreateObject("")
  On Error GoTo 0

  ' Find MapViewer and create a pointer to the application object
  Set mvApp = GetObject(,"MapViewer.Application")
  Set plot = mvApp.ActiveDocument
  ' Copy the map

  ' Get output file name from user
  ' Default to GSM name/loc w diff extension
  strFull = plot.FullName
  ln = Len(strFull)

  i = InStrRev(strFull,"\")
  If i = 0 Then
    strDir = "C:\"
    strDir = Left(strFull,i)
  End If

  j = InStrRev(strFull,".")
  If j = 0 Then
    strName = Right(strFull,ln-i) + ".pdf"
    strName = Mid(strFull,i+1,j-i) + "pdf"
  End If

  strFile = GetFilePath(strName,"pdf",strDir,"Save PDF As",3)
  ' Need to handle cancel from file dialog
  If strFile = "" Then Exit Sub
  ' Convert to URL format
  strURL = "file:///" + Replace(strFile,"\","/")

  ' Create the desktop and an empty writer document
  Set oDesktop= oServiceManager.createInstance("")
  Set oDocument= oDesktop.loadComponentFromURL("private:factory/swriter", _
  	"_blank", 0, Array(MakePropertyValue("Hidden",False)))

  ' Create the dispatcher and paste the clipboard contents to the document
  Set oDispatcher = oServiceManager.createInstance("")
  oDispatcher.executeDispatch(oDocument.CurrentController.Frame, ".uno:Paste", "", 0, Array())

  ' Save document in PDF
  Call oDocument.storeToURL(strURL, Array(MakePropertyValue("FilterName", "writer_pdf_Export")))
  Call oDocument.Close(True)
  Exit Sub

  MsgBox "This script requires that you have the" + vbCrLf + " application suite installed." + _
  	vbCrLf + "It is available from ."

End Sub

Function MakePropertyValue(cName, uValue) As Object
  Dim oServiceManager As Object
  Set oServiceManager = CreateObject("")
  Dim oStruct
  Set oStruct = oServiceManager.Bridge_GetStruct("")
  oStruct.Name = cName
  oStruct.Value = uValue
  Set MakePropertyValue = oStruct
End Function


Updated November 2, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.