Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a series of map layers is it possible to arrange them in some order, add basic map features (north arrow, scale bar) and then save the result as a JPG. I'd like to accomplish this in the background as a button-triggered event in an ArcMap Add-On.

I've seen ExportActiveView, but I think this will only work if I have the map layers already loaded into the ActiveView and on the users' screen.

Is it possible to create this map behind the scenes?

share|improve this question
I'm guessing your question at… provides a little more background in a different context (for instance that your data lives in a File GeoDatabase, etc)? It doesn't bother me, I am just curious if this is correct. – elrobis May 4 '12 at 15:08
@Radar, FYI this all may be done using python/arcpy too. Adding layers and exporting map. It will take more less code to develop. You could just reference a template mxd that has your layout controls already positioned and created. – artwork21 May 4 '12 at 15:42
@elrobis You can consider that question irrelevant for the purpose of this one - I just have map layers coming in and I need a JPG out, all done in the background (e.g. not on screen). – Radar May 4 '12 at 18:49
up vote 7 down vote accepted

Something similar I have done in the past is use IMapDocument. It does require a hard file, so I just create a temp file for the process, and delete after the export. In the code snippet below, the MapExportFormat is a little enumerator I created representing different output formats (pdf,gif,png).

private static void ExportMap(IMapDocument map,MapExportFormat exportFormat, string outputFile)
            int OUTPUT_RES = 600;
            IExport export = null;

            switch (exportFormat)
                case MapExportFormat.PDF:
                    IExportPDF pdfExport = new ExportPDFClass();
                    pdfExport.ImageCompression = esriExportImageCompression.esriExportImageCompressionDeflate;
                    pdfExport.EmbedFonts = true;
                    pdfExport.Compressed = true;
                    //IExportPDF2 pdfExport2 = (IExportPDF2)pdfExport;
                    //pdfExport2.ExportPDFLayersAndFeatureAttributes = esriExportPDFLayerOptions.esriExportPDFLayerOptionsLayersOnly;
                    export = (IExport)pdfExport;
                case MapExportFormat.GIF:
                    IExportGIF gifExport = new ExportGIFClass();
                    export = (IExport)gifExport;
                case MapExportFormat.JPG:
                    IExportJPEG jpgExport = new ExportJPEGClass();
                    export = (IExport)jpgExport;
                case MapExportFormat.PNG:
                    IExportPNG pngExport = new ExportPNGClass();
                    export = (IExport)pngExport;


            export.Resolution = OUTPUT_RES;
            export.ExportFileName = outputFile;

            tagRECT exportFrame = map.ActiveView.ExportFrame;
            IEnvelope exportEnvelope = new EnvelopeClass();
            exportEnvelope.PutCoords(exportFrame.left,, exportFrame.right, exportFrame.bottom);
            export.PixelBounds = exportEnvelope;

            int hdc = export.StartExporting();
            map.ActiveView.Output(hdc, OUTPUT_RES,exportFrame,null,null);
share|improve this answer
Thanks for the reply and code snippet. In your example does all of the work happen off-screen? Can ActiveView be used without actually showing it to the user in ArcMap? – Radar May 4 '12 at 18:51
Sure does. I did everything from a button click in a form totally outside of ArcMap. – user890 May 4 '12 at 19:19
Thanks a lot for the help. One additional point. When working from within an ESRI Add-On and exporting a map document that is not currently on screen, it's best to set the activeView to mapdoc.PageLayout - if you don't set it to the layout view the map unit-to-pixel conversion gets mangled and you end up with image dimensions that are very large and can't be handled by the export.FinishExporting method - it error checks this. – Radar May 7 '12 at 23:23
How do you create the IMapDocument? In my example i had to create a dummy mxd. Like: IMapDocument ipMapDoc; ipMapDoc = new MapDocumentClass(); ipMapDoc.Open(@"D:\Data\Spatial\Untitled.mxd"); Is there any way to get around this? – user8045 Jun 7 '12 at 8:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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