Collaborating in geospatial context since 2000!

Monday, June 09, 2008

Map2PDF Software Integration

Can I customize my export to GeoPDF from ArcGIS? Of course you can!!! TerraGo has included a series of COM interfaces and objects which allows each user to customize their workflow. To get more information on this, please check out the compiled help that installs with the software. I included a little VBA routine that anyone can cut and paste in to the VBA compiler that installs with ArcGIS.

Sub ExportToGeoPDF()

' simple sample code presumes a specific, known MXD and uses a hardcoded output name

Dim fileName As String
fileName = "C:\temp\engine_geopdf2.pdf"

Dim pMxDocument As IMxDocument
Set pMxDocument = ThisDocument

Dim pPageLayout As IPageLayout
Set pPageLayout = pMxDocument.PageLayout

Dim pActiveView As IActiveView
Set pActiveView = pPageLayout

Dim pMap As IMap
Set pMap = pMxDocument.Maps.Item(0)
If pMap Is Nothing Then Exit Sub

Dim pLayer As ILayer
Set pLayer = pMap.Layer(0)
If pLayer Is Nothing Then Exit Sub

' cocreate the exporter
Dim pExport As IExport
Set pExport = New ExportGeoPDF
Dim pExport2 As IExportGeoPDF2
Set pExport2 = pExport

Dim pConfig As IGeoPDFConfig
Set pConfig = pExport

' set global options: PDF layering and PDF annotation type
pConfig.Layering = True
Config.Compatibility = geoPDFAnnotType.geoPDFAnnotTypeObjectData

' set the layer to receive PDF annotations
pConfig.PutAnnotate pLayer, True

' the rest is like any other exporter - except that IActiveView.Output is unnecessary

pExport.ExportFileName = fileName
pExport.Resolution = 300

Dim tmpDC As Long
tmpDC = GetDC(0)
Dim screenResolution As Integer
screenResolution = GetDeviceCaps(tmpDC, 88)
ReleaseDC 0, tmpDC

Dim scaleFactor As Double
scaleFactor = pExport.Resolution / screenResolution

Dim exportRECT As tagRECT
With exportRECT
.Left = pActiveView.ExportFrame.Left * scaleFactor
.Top = pActiveView.ExportFrame.Top * scaleFactor
.Right = pActiveView.ExportFrame.Right * scaleFactor
.bottom = pActiveView.ExportFrame.bottom * scaleFactor
End With

Dim pPixelBoundsEnv As IEnvelope
Set pPixelBoundsEnv = New Envelope
pPixelBoundsEnv.PutCoords exportRECT.Left, exportRECT.Top, exportRECT.Right, exportRECT.bottom

pExport.PixelBounds = pPixelBoundsEnv

Dim hdc As Long
hdc = pExport.StartExporting

' the usual call to IActiveView.Output at this point that is required by other exporters is not needed


End Sub

Labels: , ,


Anonymous Anonymous said...

10:41 AM EDT

Anonymous Anonymous said...

If you're a Mac software developer or a die-hard fan, you probably know that WWDC is Apple's World Wide Developer Conference. Apple hosts sessions to teach about development tools and related topics and they also give labs to sit and talk to the people that designed the Apple's systems.

3:11 AM EDT


Post a Comment

<< Home