0

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;
  • 1
    This code works fine for me at 10.2.2 using a form and a button, so I'm not sure what is causing the issue for you. But you could try opening the form modally, ie form.ShowDialog(). That would prevent users from interacting with the map until the form is closed. – Dan Jurgella Jun 17 '16 at 14:40
  • Using a modal dialog doesn't solve the problem. Moving the modal dialog interupts the export, too. But as you correctly mentioned, running my AddIn under ArcGIS 10.2.2 works as expected and exports the PDF completely. – Propper Jun 24 '16 at 9:36
0

This seems to be a bug in ArcGIS 10.0. As workaround one can call the menu item ‘expot map’ directly. The file chooser and the different export settings can be done by using this ESRI standard tool. Here is the corresponding code:

//Command:  Export Map 
//CLSID: {119591DB-0255-11D2-8D20-080009EE4E51}
//ProgID: esriArcMapUI.MxFileMenuItem
//Toolbar (Parent): File_Menu   
//SubType: 9
//Description: Export map to graphics file
object helpme = "{119591DB-0255-11D2-8D20-080009EE4E51}";
ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
uid.Value = helpme;
uid.SubType = 9;

ESRI.ArcGIS.Framework.ICommandBars commandBars = ArcMap.Application.Document.CommandBars;  
ESRI.ArcGIS.Framework.ICommandItem commandItem = commandBars.Find(uid, false, false);
if (commandItem != null)
{
    if (commandItem.Name == "File_Export")
    {
        commandItem.Execute();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.