How to print a map with .net runtime 100.2

4964
13
01-11-2018 06:49 AM
Jean-ChristopheBertolini
New Contributor III

Hi,

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 ?

Thanks!

jcb 

0 Kudos
13 Replies
dotMorten_esri
Esri Notable Contributor

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.

0 Kudos
Jean-ChristopheBertolini
New Contributor III

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 ?

0 Kudos
dotMorten_esri
Esri Notable Contributor

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.

0 Kudos
DrewD
by
New Contributor III

What would be the easiest way to play around with scales (say if you wanted smaller scale for higher detail)? 

0 Kudos
WesBailes
New Contributor III

Anything planned for the future for exporting/printing?  To me that's one of the drawbacks of using Runtime SDK vs. ArcGIS Engine.  Thanks!

0 Kudos
WaldemarNowak
New Contributor III

Was it fixed in 100.5 ?

0 Kudos
JoeHershman
MVP Regular Contributor
RenderTargetBitmap bitmap = new RenderTargetBitmap((int)mapView.ActualWidth, (int)mapView.ActualHeight, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(mapView);

using (Stream s = File.Create(outputfile))
{
     BitmapEncoder encoder = new PngBitmapEncoder();
     encoder.Frames.Add(BitmapFrame.Create(bitmap));
     encoder.Save(s);
}
Thanks,
-Joe
0 Kudos
dotMorten_esri
Esri Notable Contributor

Here's a slightly simpler way:

var img = await mapView.ExportImageAsync();
var pngImg = await img.GetEncodedBufferAsync();

0 Kudos
WaldemarNowak
New Contributor III

The example given by Morten using 

ExportImageAsync

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):

bitmap.Render(mapView);

 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?

Regards,

Waldek

0 Kudos