Hi everyone,
I have a problem with Arcobjects SDK C#. I want to export a MXD to PDF, AI and PNG.
The PDF and AI Export works fine but not the PNG Export.
When I export to PNG, I have this error : Exception de HRESULT : 0x80040334
My call :
IMapDocument pMapDoc = new MapDocument();
pMapDoc.Open(folderFileMXD + nameFile + ".mxd");
IActiveView m_ActiveView = pMapDoc.ActiveView;
ExportActiveViewParameterized(nameFile, m_ActiveView, 300, 1, "PNG", folderFilePNG, false);
My function :
private static void ExportActiveViewParameterized(string fileName, IActiveView docActiveView, int iOutputResolution, int lResampleRatio, string ExportType, string sOutputDir, Boolean bClipToGraphicsExtent)
{
try
{
IExport docExport;
IPrintAndExport docPrintExport;
IOutputRasterSettings RasterSettings;
// The Export*Class() type initializes a new export class of the desired type.
if (ExportType == "PDF")
{
docExport = new ExportPDFClass();
}
else if (ExportType == "AI")
{
docExport = new ExportAIClass();
}
else if (ExportType == "PNG")
{
docExport = new ExportPNGClass();
}
else
{
ExportType = "EMF";
docExport = new ExportEMFClass();
}
docPrintExport = new PrintAndExportClass();
docExport.ExportFileName = sOutputDir + fileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];
//// check if export is vector or raster
if (docExport is IOutputRasterSettings)
{
// for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time
RasterSettings = (IOutputRasterSettings)docExport;
RasterSettings.ResampleRatio = (int)lResampleRatio;
}
docPrintExport.Export(docActiveView, docExport, 300, bClipToGraphicsExtent, null);
}
catch (Exception e)
{
Log.Error("FAILURE");
Log.Error(e.Message);
Log.Error(e.StackTrace);
}
}
Do you have an idea of the problem ?
Thanks in advance
Looking at the API help file the IOutputRasterSettings interface is not implemented by ExportPNG class. May be that is the issue?
I tested this code snippet and both PDF and PNG worked well for me. Though typically it is recommended to activate the active view before use (please refer to http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//0012000008m6000000), seems like this is not the issue for you here. I would recommend to test it in ArcMap add-in first. You may also try with other mxd files.
Sorry for my late answer. It works.
Thank you very much.
What did you do? It would be useful for others to know how you solved it rather than just saying "it works".
You have right.
I jave used this example : arcobjects-sdk-community-samples/ExportActiveViewCS_Net.cs at master · Esri/arcobjects-sdk-community...