Skip to main content

Printing and Exporting

  • 4 minutes to read

The Map control makes it possible to print a map and export it to numerous file formats.

MapPrintingExporting

Make sure that your project references the DevExpress.Xpf.Printing.24.1 and DevExpress.Printing.v24.1.Core assemblies to be capable to perform the following tasks.

Invoke the Print Preview Window

Use one of the following methods to invoke the Print Preview with a toolbar or the Print Preview with a Ribbon.

Method Description
MapControl.ShowPrintPreview Invokes the Print Preview window, which shows the print preview of the Map control.
MapControl.ShowPrintPreviewDialog Invokes the modal Print Preview window, which shows the print preview of the Map control.
MapControl.ShowRibbonPrintPreview Invokes the Print Preview window with a Ribbon for the Map control.
MapControl.ShowRibbonPrintPreviewDialog Invokes the Print Preview modal dialog with a Ribbon for the Map control.

The code below shows how to invoke the Print Preview form with the Ribbon on the button click event.

private void onButtonClick(object sender, RoutedEventArgs e) {
      mapControl.ShowRibbonPrintPreviewDialog(this);
}

The Print Preview allows you to immediately print a map using default settings or to configure the required options before printing.

  1. To print a map using the default printer and predefined settings, click Quick Print.

  2. To change settings before printing, select the Print… item.

    In the Print… dialog, configure settings and click OK to print a map.

    MapPrintDialog

Export a Map

The Map control provides several ways to export a map.

  1. To export a map to the desired file format from code, use one of the following methods.

    Property Description
    MapControl.ExportToHtml Exports a map to an HTML file.
    MapControl.ExportToImage Exports a map to an image.
    MapControl.ExportToMht Exports a map to an MHT file.
    MapControl.ExportToPdf Exports a map to a PDF file.
    MapControl.ExportToRtf Exports a map to an RTF file.
    MapControl.ExportToXls Exports a map to an XLS file.
    MapControl.ExportToXlsx Exports a map to an XLSX file.
    MapControl.ExportToXps Exports a map to an XPS file.
    MapControl.ExportToDocx Exports a map to a DOCX file.

    The code below shows how to export a map to the specified PDF file on the button click event.

    private void onButtonClick(object sender, RoutedEventArgs e) {
          mapControl.ExportToPdf("D://document.pdf");
    }
    

    In addition, you can export a map vector layer’s content to one of the supported formats using the following methods.

    Method Description
    VectorLayerBase.ExportToKml Exports data from a vector layer using the KML file format.
    VectorLayerBase.ExportToSvg Exports data from a vector layer using the SVG file format.
    VectorLayerBase.ExportToShp Exports vector layer data to the specified shapefile.

    Use the following code to export the map’s vector data to the specified KML file.

    private void onButtonClick(object sender, EventArgs e) {
            vectorLayer.ExportToKml("D://file.kml");
    }
    
  2. You can export a map using the Print Preview window. To do this, select the desired format in the Export item’s drop-down list.

    In the Export Document… window, configure exporting options and click OK.

    MapExportOptions

Configure Map Print/Export Settings

It is possible to change the map’s print/export options, for instance, size mode. To do this, use the following markup.

<dxm:MapControl x:Name="mapControl">
      <dxm:MapControl.PrintOptions>
            <dxm:MapPrintOptions SizeMode="Zoom" 
                                 PrintMiniMap="False"/>
      </dxm:MapControl.PrintOptions>
      <!--...-->
</dxm:MapControl>

The code above uses the following classes and properties.

Class or Property Description
MapControl.PrintOptions Gets or sets print options of the Map control.
MapPrintOptions Stores map print options.
MapPrintOptions.PrintMiniMap Specifies whether to print/export a mini map.
MapPrintOptions.SizeMode Specifies a map size mode. To set this property, use items of the MapPrintSizeMode enumeration.
See Also