Printing and Exporting
- 4 minutes to read
The Map control allows you to print and export a map and its vector layer items to multiple formats.
Make sure that your project references the DevExpress.XtraPrinting.24.1 and DevExpress.Printing.v24.1.Core assemblies to be capable of completing the following tasks.
- Immediately Print a Map
- Print a Map Using the Standard Print Dialog
- Print/Export a Map Using the Print Preview
- Export a Map from Code
- Configure Print/Export Options
Immediately Print a Map
To immediately print the Map control’s content without invoking any print dialogs, use the MapControl.Print method.
Print a Map Using the Standard Print Dialog
You can show the standard print dialog before map printing as the following image demonstrates.
To show the default print dialog before printing, use the MapControl.ShowPrintDialog method.
Print/Export a Map Using the Print Preview
To show the Print Preview dialog with a toolbox or with a Ribbon, use one of the following methods.
Method | Description |
---|---|
MapControl.ShowPrintPreview | Invokes the Print Preview with a toolbox. |
MapControl.ShowRibbonPrintPreview | Invokes the Print Preview with a Ribbon. |
The code below shows how to invoke the Ribbon Print Preview.
private void onButtonClick(object sender, RoutedEventArgs e) {
mapControl.ShowRibbonPrintPreview(this);
}
To immediately print a map using the Print Preview, select the Quick Print item.
To invoke the standard print dialog before printing, select the Print item in the Print Preview.
To export a map using the Print Preview dialog, select the desired file format in the Export item’s drop-down list.
Export a Map from Code
All the map data can be exported to numerous file formats. For this, use the appropriate method from the table below.
Method | Description |
---|---|
MapControl.ExportToImage | Exports a map to an image. |
MapControl.ExportToPdf | Exports a map to a PDF file. |
MapControl.ExportToMht | Exports a map to an MHT 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. |
The following code shows how to export a map to the specified PDF file.
private void onButtonClick(object sender, EventArgs 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 |
---|---|
MapItemsLayerBase.ExportToKml | Exports data from a vector layer using the KML file format. |
MapItemsLayerBase.ExportToSvg | Exports data from a vector layer using the SVG file format. |
MapItemsLayerBase.ExportToShp | Exports vector layer data to the specified shapefile. |
Use the following code to export map vector data to the specified KML file.
private void onButtonClick(object sender, EventArgs e) {
vectorLayer.ExportToKml("D://file.kml");
}
Configure Print/Export Option
To configure printing/exporting options, you can use the following code example.
private void onButtonClick(object sender, EventArgs e) {
mapControl.PrintOptions.PrintMiniMap = true;
mapControl.PrintOptions.PrintNavigationPanel = true;
mapControl.PrintOptions.PrintOverlays = true;
mapControl.PrintOptions.SizeMode = MapPrintSizeMode.Zoom;
mapControl.Print();
}
The code above uses the following API members.
Member | Description |
---|---|
MapControl.PrintOptions | Provides access to map print/export options. |
PrintOptions.PrintMiniMap | Specifies a value indicating whether to print/export a mini map. |
PrintOptions.PrintNavigationPanel | Specifies a value indicating whether to print/export a navigation panel. |
PrintOptions.PrintOverlays | Specifies a value indicating whether to print/export map overlays. |
PrintOptions.SizeMode | Specifies a map size mode. To set this property, use the MapPrintSizeMode enumeration items. |