Printing not working

839
6
02-24-2011 04:08 AM
MarkBaird
Esri Regular Contributor
I'm trying to use silverlight printing to print a map.

Now it all works fine if you print a map which is visible in your silverlight application using standard silverlight printing methods.  The only problem is that I want my prints to fill the page I'm printing on and not be constrained by the screen size!

This article tells you how to do it, however if you introduce a map, it prints the control, but it never shows any map layers.

http://www.silverlightshow.net/items/Advanced-printing-in-Silverlight-4.aspx

So basically I've created a user control which contains a map and some text blocks for header and footer information.  If I add the map to the layoutRoot on my silverlight application is displays fine (it fires the Progress event of the map cotrol).

However if I make an instance of the control and set this as the item I want to print, everything on the control prints including header for footer information I've created, but the map remains blank (although it fills the page which is what I wanted).  In fact it remains blank because it doesn't draw the layers as I can see the Progress event is never fired.

What is going on here?  Is there anyway of printing a map control which isn't attached to the visible part of the silverlight applicaiton?  How can you force it to draw?

WYSIWYG printing isn't very good in a map browser as the screen size isn't the same as the paper!

Help appreciated

Thanks!
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
The issue is probably that a layer can't be included in many maps. So if you want at the same time the main map and a preview of the print, you need to clone the layers for previewing them.

This is done this way is this print sample: http://www.arcgis.com/home/item.html?id=e361c2cc69784fcba34358d0458f66e3
0 Kudos
MarkBaird
Esri Regular Contributor
I'm creating all of the layers in my printMap control by phically adding them in again.  For example:

                //Bing Layer
                ESRI.ArcGIS.Client.Bing.TileLayer bingLayer = new ESRI.ArcGIS.Client.Bing.TileLayer
                {
                    ID = "BingLayer",
                    LayerStyle = ESRI.ArcGIS.Client.Bing.TileLayer.LayerType.Road,
                    Visible = true,
                    ServerType = ESRI.ArcGIS.Client.Bing.ServerType.Production,
                    Token = Application.Current.Resources["BingKey"].ToString()
                };
                printMap.Layers.Add(bingLayer);

The problem is if I display my control, like this I can print:

            //create the printer view
            printerView = new PrinterView();
            LayoutRoot.Children.Add(printerView);

Once it has drawn, then you can call the following:

            PrintDocument printHandler = new PrintDocument();
           
            printHandler.PrintPage += new EventHandler<PrintPageEventArgs>(printHandler_PrintPage);
            printHandler.Print("Print Page");


But if I create the PrinterView and don't add it to LayoutRoot and send it to the Print methods you always get a blank map.

I need a way of forcing the Map control to redraw.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
One option is you to create a popup (with an opacity set to 0.0 if you want it hidden), and put your printerView (or your main control containing the map) inside this popup.
0 Kudos
MarkBaird
Esri Regular Contributor
Well I've tried it and it kind of works.  Only problem is if you size the control to your paper (A4 for example) it is bigger than the dimensions of your screen.  If you print something bigger than your screen it gets cropped by the Silverlight print methods.  This why you don't have it connected to your GUI (as in the link in my first post).  WSYIWYG printing isn't what I want, I need to dimension my prints so they fill the paper.

I like a challenge!:D
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Did you try with a popup?
As far as I remember, I think there is no limitation to the screen size with a popup.

And for sure the sample I pointed out is working when printing (with or without preview) to a printer bigger than the screen (A2, A1, A0).
0 Kudos
MarkBaird
Esri Regular Contributor
Had a productive day once I'd discovered that once you land your grid that you want to print within a ScrollViewer the size restrictions go away...

I've now got printing that fills the paper!

Thanks for the help!
0 Kudos