KB no longer maintained - MapViewer is a Legacy Product. Legacy Products are still supported, but no longer receive new features or updates. Many of MapViewer's features have been moved to Surfer. Please contact support@goldensoftware.com with any questions. |
This article contains a sample script for creating a vector PDF file using OpenOffice application.
To run this script:
- Copy the script below, or click here to download the BAS file: Export_Plot_to_OpenOfficePDF.BAS.
- In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
- Double click on Scripter.exe to launch Scripter.
- Press Ctrl+A to select all of the existing lines then press Delete.
- 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.
- Click Script | Run to run the script.
*********
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Export_Plot_to_OpenOfficePDF.bas ' Copyright (C) Golden Software Inc. 1992-2018 ' ' Uses the OpenOffice To create a vector PDF. ' ' This script requires that you have OpenOffice. ' It is available for free from http://www.openoffice.org/. ' ' 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("com.sun.star.ServiceManager") 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 plot.CopyAllLayers() ' 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:\" Else strDir = Left(strFull,i) End If j = InStrRev(strFull,".") If j = 0 Then strName = Right(strFull,ln-i) + ".pdf" Else 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("com.sun.star.frame.Desktop") 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("com.sun.star.frame.DispatchHelper") 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 NeedOOo: MsgBox "This script requires that you have the" + vbCrLf + "OpenOffice.org application suite installed." + _ vbCrLf + "It is available from http://www.openoffice.org/ ." End Sub Function MakePropertyValue(cName, uValue) As Object Dim oServiceManager As Object Set oServiceManager = CreateObject("com.sun.star.ServiceManager") Dim oStruct Set oStruct = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue") oStruct.Name = cName oStruct.Value = uValue Set MakePropertyValue = oStruct End Function
Updated May 22, 2018
Comments
0 comments
Please sign in to leave a comment.