EMF files are native Windows graphics files that can contain a mixture of vector and raster data.
They are useful for embedding in Windows documents because the vector portions of the EMF can be resized without loss of quality.
However, since EMF does not support font embedding and is exclusively a Windows format, it is not commonly used as an interchange format between users.
//This example demonstrates how to export a layout to EMF.
//Added references
using ArcGIS.Desktop.Core; //Project
using ArcGIS.Desktop.Layouts; //Layout classes
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //Export formats
publicclass ExportLayoutToEMFExample
{
publicstatic Task ExportLayoutToEMFAsync(string LayoutName, string Path)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
if (layoutItem == null)
return Task.FromResult<Layout>(null);
//Create EMF format with appropriate settings
EMFFormat EMF = new EMFFormat();
EMF.Resolution = 300;
EMF.OutputFileName = Path;
return QueuedTask.Run(() =>
{
//Export Layout
Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
if (EMF.ValidateOutputFilePath())
{
lyt.Export(EMF);
}
});
}
}
//This example demonstrates how to export an individual map frame on a layout to EMF.
//Added references
using ArcGIS.Desktop.Core; //Project
using ArcGIS.Desktop.Layouts; //Layout classes
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //Export formats
publicclass ExportMapFrameToEMFExample
{
publicstatic Task ExportMapFrameToEMFAsync(string LayoutName, string MFName, string Path)
{
//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
if (layoutItem == null)
return Task.FromResult<Layout>(null);
//Create EMF format with appropriate settings
EMFFormat EMF = new EMFFormat();
EMF.Resolution = 300;
EMF.OutputFileName = Path;
return QueuedTask.Run(() =>
{
//Export MapFrame
Layout lyt = layoutItem.GetLayout(); //Loads and returns the layout associated with a LayoutItem
MapFrame mf = lyt.FindElement(MFName) as MapFrame;
EMF.OutputFileName = Path;
if (EMF.ValidateOutputFilePath())
{
mf.Export(EMF);
}
});
}
}
//This example demonstrates how to export the active mapview to EMF.
//Added references
using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask
using ArcGIS.Desktop.Mapping; //MapView and Export formats
publicclass ExportActiveMapToEMFExample
{
publicstatic Task ExportActiveMapToEMFAsync(string Path)
{
return QueuedTask.Run(() =>
{
//Reference the active map view
MapView map = MapView.Active;
//Create EMF format with appropriate settings
EMFFormat EMF = new EMFFormat();
EMF.Resolution = 300;
EMF.Height = 500;
EMF.Width = 800;
EMF.OutputFileName = Path;
//Export active map view
if (EMF.ValidateOutputFilePath())
{
map.Export(EMF);
}
});
}
}