Back to Devexpress

Printing and Exporting

windowsforms-118241-controls-and-libraries-map-control-end-user-features-printing-and-exporting.md

latest9.0 KB
Original Source

Printing and Exporting

  • Oct 29, 2020
  • 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.25.2 and DevExpress.Printing.v25.2.Core assemblies to be capable of completing the following tasks.

Immediately Print a Map

To immediately print the Map control’s content without invoking any print dialogs, use the MapControl.Print method.

csharp
private void onButtonClick(object sender, EventArgs e) {
        mapControl.Print();
}
vb
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.

csharp
private void onButtonClick(object sender, EventArgs e) {
        mapControl.ShowPrintDialog();
}
vb
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.

MethodDescription
MapControl.ShowPrintPreviewInvokes the Print Preview with a toolbox.
MapControl.ShowRibbonPrintPreviewInvokes the Print Preview with a Ribbon.

The code below shows how to invoke the Ribbon Print Preview.

csharp
private void onButtonClick(object sender, RoutedEventArgs e) {
      mapControl.ShowRibbonPrintPreview(this);
}
vb
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

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.

MethodDescription
MapControl.ExportToImageExports a map to an image.
MapControl.ExportToPdfExports a map to a PDF file.
MapControl.ExportToMhtExports a map to an MHT file.
MapControl.ExportToRtfExports a map to an RTF file.
MapControl.ExportToXlsExports a map to an XLS file.
MapControl.ExportToXlsxExports a map to an XLSX file.

The following code shows how to export a map to the specified PDF file.

csharp
private void onButtonClick(object sender, EventArgs e) {
        mapControl.ExportToPdf("D://document.pdf");
}
vb
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.

MethodDescription
MapItemsLayerBase.ExportToKmlExports data from a vector layer using the KML file format.
MapItemsLayerBase.ExportToSvgExports data from a vector layer using the SVG file format.
MapItemsLayerBase.ExportToShpExports vector layer data to the specified shapefile.

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

csharp
private void onButtonClick(object sender, EventArgs e) {
        vectorLayer.ExportToKml("D://file.kml");
}
vb
Private Sub onButtonClick(sender As Object, e As EventArgs)
    vectorLayer.ExportToKml("D://file.kml")
End Sub

Configure Print/Export Option

To configure printing/exporting options, you can use the following code example.

csharp
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();            
}
vb
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.

MemberDescription
MapControl.PrintOptionsProvides access to map print/export options.
PrintOptions.PrintMiniMapSpecifies a value indicating whether to print/export a mini map.
PrintOptions.PrintNavigationPanelSpecifies a value indicating whether to print/export a navigation panel.
PrintOptions.PrintOverlaysSpecifies a value indicating whether to print/export map overlays.
PrintOptions.SizeModeSpecifies a map size mode. To set this property, use the MapPrintSizeMode enumeration items.

See Also

How to: Print a Map

How to: Export a Map

How to: Export Selected Map Items to an Image

Document Viewer