I have developed an ArcMap extension in C# for ArcGIS 10.0 with a Form that configures the PageLayout and exports the ActiveView as PDF. There are two different ways to do that. You could use
IPrintAndExport.Export function or you could use the
IActiveView.Output function. Both ways generally work fine and export a PDF document as expected as long as the user is patient enough to wait for the export to finish without clicking somewhere or moving the dialog. If the user can’t keep his finger still during the exporting, there seems to be thrown an event that forces a refresh on the ActiveView, immediately interrupts the map export and generates half-finished pdf. I just tried to prevent the user to do something by implementing an
IProgressDialog2 but again with the same result. When the user moves the
IProgressDialog2 map export stops again.
When I use the ESRI GUI standard function accessible through the main menu ‘file --> export map’ the whole ArcMap application is freezed during the export. So every click of the user is ignored and the map export is finished successfully. Any idea how to do this in arcobjects? Or is there a different solution?
Attached you will find my source code:
string exportFileName = @"C:\test.pdf"; double screenresolution = 96.0; IExportPDF pdfExport = new ExportPDFClass(); IExport export = (IExport)pdfExport; export.Resolution = 300; export.ExportFileName = exportFileName; ESRI.ArcGIS.esriSystem.tagRECT exportFrame = ((IActiveView)m_mxDoc.ActiveView).ExportFrame; double right = exportFrame.right * export.Resolution / screenresolution; double bottom = exportFrame.bottom * export.Resolution / screenresolution; exportFrame.right = (int)(right); exportFrame.bottom = (int)(bottom); IEnvelope pDisplayEnv = new EnvelopeClass(); pDisplayEnv.PutCoords(exportFrame.left, exportFrame.top, exportFrame.right, exportFrame.bottom); export.PixelBounds = pDisplayEnv; Cursor.Current = Cursors.WaitCursor; int hdc = export.StartExporting(); m_mxDoc.ActiveView.Output(hdc, (int) export.Resolution, exportFrame, null, null); export.FinishExporting(); export.Cleanup(); Cursor.Current = Cursors.Default;