Hi
We are migrating an application in 9.2 to version 10.
The following VB code. NET converted to PDF in version 9.2 but returns a blank page used in Arcgis 10.
Anyone know how to export to PDF the active layout (SDK. NET ArcGis 10)?
Thanks in advance (JMJ98)
'------------------------
'variables
Dim lScrRes As Long
Dim pExporter As IExporter
Dim deviceRECT As tagRECT
Dim pDriverBounds As IEnvelope
Dim pCancel As ITrackCancel
Dim nomExportacio As String
Dim pExport As IExport
Dim iScreenResolution As Integer
Dim iOutputResolution As Integer
Dim exportRECT As tagRECT
Dim pPixelBoundsEnv As IEnvelope
Dim hdc As Long
Dim deviceFrameRect As tagRECT
Dim pActiveView As IActiveView
Dim tmpDC As Long
Dim faExportacio As Boolean
Dim formatoImagen As String
Dim pMxDoc As IMxDocument
Dim objFactory As IObjectFactory
Dim nom As String
Dim pageL As IPageLayout
Dim map As IMap
Dim psi As New ProcessStartInfo()
'------------------------
......
faExportacio = False
pActiveView = pMxDoc.PageLayout
pageL = New PageLayout
pageL = pActiveView
If formatoImagen = "PDF" Then
pExporter = objFactory.Create("esriOutput.PDFExporter")
nomExportacio = nom
pExporter.ExportFileName = nomExportacio
With deviceFrameRect
.left = 0
.right = 800
.top = 0
.bottom = 600
End With
'pActiveView.ScreenDisplay.DisplayTransformation.DeviceFrame = deviceFrameRect
tmpDC = GetDC(0)
iScreenResolution = GetDeviceCaps(tmpDC, 88) '88 is Win32 constant for LOGPIXELSX
ReleaseDC(0, tmpDC)
iOutputResolution = 1200
pExporter.Resolution = iOutputResolution
With exportRECT
.left = pActiveView.ExportFrame.left * (iOutputResolution / iScreenResolution)
.top = pActiveView.ExportFrame.top * (iOutputResolution / iScreenResolution)
.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution)
.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution)
End With
pPixelBoundsEnv = New Envelope
pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom)
pExporter.PixelBounds = pPixelBoundsEnv
hdc = pExporter.StartExporting
pCancel = New CancelTracker
pActiveView.Output(hdc, iOutputResolution, exportRECT, pageL.Page.PrintableBounds, pCancel)
pExporter.FinishExporting()
faExportacio = True
psi.FileName = System.Windows.Forms.Application.StartupPath.ToString & "\tmp\" & cmbParametro.Text & ".pdf"
Process.Start(psi)
End If
'------------------------
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.SpecialFolder.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
What do you mean by "if runs in a windows form application (with automated arcgis opened)"..Please can be clear on the same...or any screen ?
Hi (sorry for my english)
From an application in VB.NET and try to open an ArcMap print your layout. (Automation)
We have included the sample code (ExportActiveView) and get a blank PDF.
In contrast, using the same example with ArcMap works perfectly.
JMJ98
Somehow you have to play with focus pagelayout... not basically activeview...
I've not had a chance to step through the code yet but wanted to at least mention that the ArcPy site package has simple functions to export to pdf. We have documentation in the SDK regarding calling python scripts from .NET if this sounds like an alternative you may be interested in.
I don't have a solution for export from .NET aplication to PDF.
VBA runs but the same code from my VB .NET application fails and returns a blank PDF. I think that error have a difficult solution ....
Maybe its the moment of on arcpy thinking, and see if runs.