ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / MapFrame Class / Export Method
ExportFormat
Example

In This Topic
    Export Method (MapFrame)
    In This Topic
    Export a layout to a variety of formats. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void Export( 
       ExportFormat exportFormat
    )
    Public Sub Export( _
       ByVal exportFormat As ExportFormat _
    ) 

    Parameters

    exportFormat
    ExportFormat
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    Multiple examples are provided with each format derived from ArcGIS.Desktop.Mapping.ExportFormat.
    Example
    ExportBMP_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to BMP.
    
    //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
    
    public class ExportMapFrameToBMPExample
    {
      public static Task ExportMapFrameToBMPAsync(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 BMP format with appropriate settings
        BMPFormat BMP = new BMPFormat();
        BMP.HasWorldFile = true;
        BMP.Resolution = 300;
        BMP.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;
          BMP.OutputFileName = Path;
          if (BMP.ValidateOutputFilePath())
          {
            mf.Export(BMP);
          }
        });
      }
    }
    ExportEMF_MapFrame
    //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
    
    public class ExportMapFrameToEMFExample
    {
      public static 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);
          }
        });
      }
    }
    ExportEPS_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to EPS.
    
    //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
    
    public class ExportMapFrameToEPSExample
    {
      public static Task ExportMapFrameToEPSAsync(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 EPS format with appropriate settings
        EMFFormat EPS = new EMFFormat();
        EPS.Resolution = 300;
        EPS.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;
          EPS.OutputFileName = Path;
          if (EPS.ValidateOutputFilePath())
          {
            mf.Export(EPS);
          }
        });
      }
    }
    ExportGIF_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to GIF.
    
    //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
    
    public class ExportMapFrameToGIFExample
    {
      public static Task ExportMapFrameToGIFAsync(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 GIF format with appropriate settings
        GIFFormat GIF = new GIFFormat();
        GIF.HasWorldFile = true;
        GIF.Resolution = 300;
        GIF.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;
          GIF.OutputFileName = Path;
          if (GIF.ValidateOutputFilePath())
          {
            mf.Export(GIF);
          }
        });
      }
    }
    ExportJPEG_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to JPEG.
    
    //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
    
    public class ExportMapFrameToJPEGExample
    {
      public static Task ExportMapFrameToJPEGAsync(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 JPEG format with appropriate settings
        JPEGFormat JPEG = new JPEGFormat();
        JPEG.HasWorldFile = true;
        JPEG.Resolution = 300;
        JPEG.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;
          if (JPEG.ValidateOutputFilePath())
          {
            mf.Export(JPEG);
          }
        });
      }
    }
    ExportPDF_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to PDF.
    
    //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
    
    public class ExportMapFrameToPDFExample
    {
      public static Task ExportMapFrameToPDFAsync(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 PDF format with appropriate settings
        PDFFormat PDF = new PDFFormat();
        PDF.Resolution = 300;
        PDF.OutputFileName = Path;
        //PDF.Password = "xxx";
    
        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;
          PDF.OutputFileName = Path;
          if (PDF.ValidateOutputFilePath())
          {
            mf.Export(PDF);
          }
        });
      }
    }
    ExportPNG_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to PNG.
    
    //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
    
    public class ExportMapFrameToPNGExample
    {
      public static Task ExportMapFrameToPNGAsync(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 PNG format with appropriate settings
        PNGFormat PNG = new PNGFormat();
        PNG.Resolution = 300;
        PNG.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;
          PNG.OutputFileName = Path;
          if (PNG.ValidateOutputFilePath())
          {
            mf.Export(PNG);
          }
        });
      }
    }
    ExportSVG_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to SVG.
    
    //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
    
    public class ExportMapFrameToSVGExample
    {
      public static Task ExportMapFrameToSVGAsync(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 SVG format with appropriate settings
        SVGFormat SVG = new SVGFormat();
        SVG.Resolution = 300;
        SVG.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;
          SVG.OutputFileName = Path;
          if (SVG.ValidateOutputFilePath())
          {
            mf.Export(SVG);
          }
        });
      }
    }
    ExportTGA_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to TGA.
    
    //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
    
    public class ExportMapFrameToTGAExample
    {
      public static Task ExportMapFrameToTGAAsync(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 TGA format with appropriate settings
        TGAFormat TGA = new TGAFormat();
        TGA.Resolution = 300;
        TGA.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;
          TGA.OutputFileName = Path;
          if (TGA.ValidateOutputFilePath())
          {
            mf.Export(TGA);
          }
        });
      }
    }
    ExportTIFF_MapFrame
    //This example demonstrates how to export an individual map frame on a layout to TIFF.
    
    //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
    
    public class ExportMapFrameToTIFFExample
    {
      public static Task ExportMapFrameToTIFFAsync(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 TIFF format with appropriate settings
        TIFFFormat TIFF = new TIFFFormat();
        TIFF.Resolution = 300;
        TIFF.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;
          TIFF.OutputFileName = Path;
          if (TIFF.ValidateOutputFilePath())
          {
            mf.Export(TIFF);
          }
        });
      }
    }
    Export a map frame to JPG
    //Export a map frame to JPG.
    
    //Create JPEG format with appropriate settings
    //BMP, EMF, EPS, GIF, PDF, PNG, SVG, TGA, and TFF formats are also available for export
    //at 2.x - JPEGFormat JPG = new JPEGFormat()
    //{
    //  HasWorldFile = true,
    //  Resolution = 300,
    //  OutputFileName = filePath,
    //  JPEGColorMode = JPEGColorMode.TwentyFourBitTrueColor,
    //  Height = 800,
    //  Width = 1200
    //};
    JPEGFormat JPG = new JPEGFormat()
    {
      HasWorldFile = true,
      Resolution = 300,
      OutputFileName = filePath,
      ColorMode = JPEGColorMode.TwentyFourBitTrueColor,
      Height = 800,
      Width = 1200
    };
    
    //Reference the map frame
    MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame;
    
    //Export on the worker thread
    await QueuedTask.Run(() =>
    {
      //Check to see if the path is valid and export
      if (JPG.ValidateOutputFilePath())
      {
        mf.Export(JPG);  //Export the map frame to JPG
      }
    });
    Export the map view associated with a map frame to BMP
    //Export the map view associated with a map frame to BMP.
    
    //Create BMP format with appropriate settings
    //EMF, EPS, GIF, JPEG, PDF, PNG, SVG, TGA, and TFF formats are also available for export
    BMPFormat BMP = new BMPFormat()
    {
      Resolution = 300,
      Height = 500,
      Width = 800,
      HasWorldFile = true,
      OutputFileName = filePath
    };
    
    //Reference the active layout view
    LayoutView lytView = LayoutView.Active;
    
    //Reference the map frame and its map view
    MapFrame mf_bmp = layout.FindElement("Map Frame") as MapFrame;
    MapView mv_bmp = mf_bmp.GetMapView(lytView);
    
    if (mv_bmp != null)
    {
      //Export on the worker thread
      await QueuedTask.Run(() =>
      {
    
        //Check to see if the path is valid and export
        if (BMP.ValidateOutputFilePath())
        {
          mv_bmp.Export(BMP);  //Export to BMP
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also