ExportActiveViewVB Sample - obtain PDF PageLayout

1025
2
01-20-2011 12:55 AM
JMJJDJM
New Contributor
Hi

This sample runs me ok, inside ArcGis 10.
But if runs in a windows form application (with automated arcgis opened), the result its blank PDF.

Please, Anyone can you help me ??

JMJ98

Sample for SDK Argis 10:

Public Sub ExportActiveViewParameterized(ByVal ExportFormat As String, ByVal iOutputResolution As Long, ByVal lResampleRatio As Long, ByVal bClipToGraphicsExtent As Boolean)

'Export the active view using the specified parameters
Dim docActiveView As IActiveView
Dim docExport As IExport
Dim docPrintAndExport As IPrintAndExport
Dim RasterSettings As IOutputRasterSettings
Dim sNameRoot As String
Dim sOutputDir As String
Dim bReenable As Boolean


If (GetFontSmoothing()) Then
bReenable = True
DisableFontSmoothing()
If (GetFontSmoothing()) Then
MsgBox("Cannot Disable Font Smoothing. Exiting.")
Return
End If
End If


docActiveView = My.ArcMap.Document.ActiveView

' Create an Export* object and cast the docExport interface pointer onto it.
' To export to any format, we simply create the desired Class here

ExportFormat = "PDF"
Select Case ExportFormat
Case "PDF"
docExport = New ExportPDF
Case "EMF"
docExport = New ExportEMF
Case "BMP"
docExport = New ExportBMP
Case "EPS"
docExport = New ExportPS
Case "SVG"
docExport = New ExportSVG
Case "GIF"
docExport = New ExportGIF
Case "TIF"
docExport = New ExportTIFF
Case "JPEG"
docExport = New ExportJPEG
Case "PNG"
docExport = New ExportPNG
Case "AI"
docExport = New ExportAI
Case Else
MessageBox.Show("Unrecognized output format, defaulting to EMF")
ExportFormat = "EMF"
docExport = New ExportEMF
End Select

docPrintAndExport = New PrintAndExport

' Output Image Quality of the export. The value here will only be used if the export
' object is a format that allows setting of Output Image Quality, i.e. a vector exporter.
' The value assigned to ResampleRatio should be in the range 1 to 5.
' 1 corresponds to "Best", 5 corresponds to "Fast"

If TypeOf docExport Is IOutputRasterSettings Then
' for vector formats, assign a ResampleRatio to control drawing of raster layers at export time
RasterSettings = docExport
RasterSettings.ResampleRatio = lResampleRatio

' NOTE: for raster formats output quality of the DISPLAY is set to 1 for image export
' formats by default which is what should be used
End If

'assign the output path and filename. We can use the Filter property of the export object to
' automatically assign the proper extension to the file.

sOutputDir = System.Environment.GetFolderPath(Environment.Speci alFolder.Personal) + "\"
sNameRoot = "VBExportActiveViewSampleOutput"
docExport.ExportFileName = sOutputDir & sNameRoot & "." & Right(Split(docExport.Filter, "|")(1), _
Len(Split(docExport.Filter, "|")(1)) - 2)

docPrintAndExport.Export(docActiveView, docExport, iOutputResolution, bClipToGraphicsExtent, Nothing)

MessageBox.Show("Finished Exporting " & sOutputDir & sNameRoot & "." & Right(Split(docExport.Filter, "|")(1), _
Len(Split(docExport.Filter, "|")(1)) - 2) & ".", "Export Active View Sample")
'cleanup for the exporter
docExport.Cleanup()

If (bReenable) Then
EnableFontSmoothing()
bReenable = False
End If
End Sub
0 Kudos
2 Replies
JohnHauck
Occasional Contributor II
Please see the following document that describes this issue in detail.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/0001000001nn000000.ht...

Specifically this section is of interest:

Creating components�??In .NET, when you use the C# or VB.NET operator, it creates the object in the driving application's process space, not in the target application (for example, ArcMap) process. Often, what you really want is to create an object in the target application process space while accessing control of it from the driving application. This sort of control is made possible by the IObjectFactory interface, obtainable from the application object.

After casting the application reference to IObjectFactory and using it to create the objects in the appropriate process space the export should no longer empty.
0 Kudos
JMJJDJM
New Contributor
Please see the following document that describes this issue in detail.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/0001000001nn000000.ht...

Specifically this section is of interest:

Creating components�??In .NET, when you use the C# or VB.NET operator, it creates the object in the driving application's process space, not in the target application (for example, ArcMap) process. Often, what you really want is to create an object in the target application process space while accessing control of it from the driving application. This sort of control is made possible by the IObjectFactory interface, obtainable from the application object.

After casting the application reference to IObjectFactory and using it to create the objects in the appropriate process space the export should no longer empty.


--------------

I do not know in which namespace I create my objects. If when you create the class MXDocument, PageLayout object is created and is the one I use for export.
It should not be complicated, in version 10 of ArcMap, export to PDF, is an operation of the most common ... Why so complicated?

I read the article and sent me a code that is the one I use to launch the ArcMap application. Add a legend to the layout (codes) but the export, only get a blank PDF.

Thanks
JMJ98
0 Kudos