I am using .ArcGIS Runtime for .Net v100.2 in a WPF app and I would like to have a function to print the map. I can't found any code samples in the documentation or in the guide. How to do this ? Could you provide exemple or link to demonstrate this ?
You would just use the WPF APIs for this. You also have the ability to call mapView.ExportImageAsync() to get a screenshot of the map, that you can then use to compose a custom print document layout.
A quick google for "Printing in WPF" gives you lots of examples how to do it, where the simples is to use the PrintDialog.PrintVisual to just print any XAML element.
Thank you for your answer. Because I am trying to migrate from the previous release 10.2.7 to 100.2, I would like to re-use server printing like this https://developers.arcgis.com/net/10-2/sample-code/ServerPrinting/
Do you know how to reach this using 100.2 API ?
The server-side print service is not available in 100.x. AFAIK there's no plans to implement it either. In my own honest opinion it was a bit of a hack with lots and lots of limitations, and I'm hoping we can provide something much better that runs client-side which ensures the print out looks exactly like what you see on the screen, which the print service was never able to do. Currently by using the client-side print APIs in WPF, you can actually get that.
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)mapView.ActualWidth, (int)mapView.ActualHeight, 96, 96, PixelFormats.Pbgra32);
using (Stream s = File.Create(outputfile))
BitmapEncoder encoder = new PngBitmapEncoder();
The example given by Morten using
works. However, it creates bitmap with the resolution of the screen. This is too low to be printed on 600 DPI printer and it cannot be zoomed. I tried to use Joe's example which looks to regard higher resolution but it generates empty bitmap (with only text "Powered by ESRI" in the right-bottom corner):
I tried also
printDialog.PrintVisual(MyMapView, "A Simple Drawing");
and it also generates empty bitmap.
Am I doing something wrong? Is there another method to print high resolution bitmap in 100.3?