windowsforms-118241-controls-and-libraries-map-control-end-user-features-printing-and-exporting.md
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.25.2 and DevExpress.Printing.v25.2.Core assemblies to be capable of completing the following tasks.
To immediately print the Map control’s content without invoking any print dialogs, use the MapControl.Print method.
private void onButtonClick(object sender, EventArgs e) {
mapControl.Print();
}
Private Sub onButtonClick(sender As Object, e As EventArgs)
mapControl.Print()
End Sub
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.
private void onButtonClick(object sender, EventArgs e) {
mapControl.ShowPrintDialog();
}
Private Sub onButtonClick(sender As Object, e As EventArgs)
mapControl.ShowPrintDialog()
End Sub
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);
}
Private Sub onButtonClick(sender As Object, e As RoutedEventArgs)
mapControl.ShowRibbonPrintPreview(Me)
End Sub
To immediately print a map using the Print Preview, select the Quick Print item.
The Print Preview
The Ribbon Print Preview
To invoke the standard print dialog before printing, select the Print item in the Print Preview.
The Print Preview
The Ribbon Print Preview
To export a map using the Print Preview dialog, select the desired file format in the Export item’s drop-down list.
The Print Preview
The Ribbon Print Preview
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");
}
Private Sub onButtonClick(sender As Object, e As EventArgs)
mapControl.ExportToPdf("D://document.pdf")
End Sub
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");
}
Private Sub onButtonClick(sender As Object, e As EventArgs)
vectorLayer.ExportToKml("D://file.kml")
End Sub
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();
}
Private Sub onButtonClick(sender As Object, e As EventArgs)
mapControl.PrintOptions.PrintMiniMap = True
mapControl.PrintOptions.PrintNavigationPanel = True
mapControl.PrintOptions.PrintOverlays = True
mapControl.PrintOptions.SizeMode = MapPrintSizeMode.Zoom
mapControl.Print()
End Sub
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. |
See Also