I have created a console application to export the active view of an MXD document using C# ArcObjects. The app works, but for some reason the exported image is missing all the layers in the map and legend. I checked, all layers are enabled, the problem is in the export implementation.
using ESRI.ArcGIS.esriSystem;
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.DataManagementTools;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.ADF.Resources;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMap;
using ESRI.ArcGIS.Geometry;
namespace firstConsole
{
class Program
{
private static LicenseInitializer m_AOLicenseInitializer = new firstConsole.LicenseInitializer();
[STAThread()]
static void Main(string[] args)
{
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
//ESRI License Initializer generated code.
m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeBasic },
new esriLicenseExtensionCode[] { });
//ESRI License Initializer generated code.
//Do not make any call to ArcObjects after ShutDownApplication()
m_AOLicenseInitializer.ShutdownApplication();
IPrintAndExport export = new PrintAndExportClass();
string mxd = @"C:\0_Work\Test\3.mxd";
tagRECT exporterRectangle;
exporterRectangle.left = 0;
exporterRectangle.bottom = 1654;
exporterRectangle.top = 0;
exporterRectangle.right = 2340;
var expOptions = new ExportJPEGClass();
expOptions.Quality = 75;
expOptions.Resolution = 200;
IMapDocument pMapDocument = new MapDocumentClass();
expOptions.ExportFileName = mxd.Replace("mxd", "jpg");
pMapDocument.Open(mxd, null);
IActiveView activeView = pMapDocument.ActiveView;
export.Export(activeView, expOptions, 200, false, null);
pMapDocument.Close();
}
}
}