Select to view content in your preferred language

Can I add a title and the legend when perform the print function?

1464
14
02-21-2011 10:41 AM
DanDong
Deactivated User
Hi all,

Is there a way to add a title and a legend to the map that I want to print? Right now I am able to print MyMap by using silverlight API.

Basically, right now, after hitting the print button, it will pop-up a window to choose the printer. I want to add a title to the map manually before this window popping up. Also the map should include the legend of the map with line shape (it represents...) and symbol (it represents....).

I dont know whether it is possible for silverlight by using API. Any suggestions? 🙂
0 Kudos
14 Replies
DominiqueBroux
Esri Frequent Contributor

Is there a way to add a title and a legend to the map that I want to print?

Sure. Instead of printing directly the map, you have to print a panel containing the map and any controls such as the legend control.

There is a print sample here : http://www.arcgis.com/home/item.html?id=e361c2cc69784fcba34358d0458f66e3
With this sample you can print the legend (e.g. print result with legend).
0 Kudos
DanDong
Deactivated User
Sure. Instead of printing directly the map, you have to print a panel containing the map and any controls such as the legend control.

There is a print sample here : http://www.arcgis.com/home/item.html?id=e361c2cc69784fcba34358d0458f66e3
With this sample you can print the legend (e.g. print result with legend).


Thank you Dominique! You mentioned in the webpage that ArcGISDynamicMapService layers don't print when the output size is greater than A2, which means that I cannot print our the A4 if I use the dynamic mapservice right?

Also, I have a question related to the codes. I cannot add this line to my codes...
using ESRI.ArcGIS.Client.Samples.MapPrinting;

and same with these three namespaces.
             xmlns:userControls="clr-namespace:MapPrinting.UserControls"
             xmlns:controls="clr-namespace:ESRI.ArcGIS.Client.Samples.MapPrinting;assembly=MapPrintingControls"
             xmlns:actions="clr-namespace:MapPrinting.Actions"

How should I add these namespaces? Thank you!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You mentioned in the webpage that ArcGISDynamicMapService layers don't print when the output size is greater than A2, which means that I cannot print our the A4 if I use the dynamic mapservice right?

I meant that the issue was with greater size than A2, so A4 and A3 is OK.

BTW, I am wondering if this limitation has not been fixed, I will have to retest with the latest version.


Also, I have a question related to the codes. I cannot add this line to my codes...
using ESRI.ArcGIS.Client.Samples.MapPrinting;

You have to build the MapPrintingControls project and, in your project, you have to add a reference to MapPrintingControls.dll.


and same with these three namespaces.
xmlns:userControls="clr-namespace:MapPrinting.UserControls"
xmlns:controls="clr-namespace:ESRI.ArcGIS.Client.Samples.MapPrinting;a ssembly=MapPrintingControls"
xmlns:actions="clr-namespace:MapPrinting.Actions"


I guess you don't need userControls and actions. xmlns:controls issue will be solved by adding a reference to MapPrintingControls.dll.
0 Kudos
DanDong
Deactivated User
You have to build the MapPrintingControls project and, in your project, you have to add a reference to MapPrintingControls.dll.


Thank you Dominique! Can I just copy the MapPrintingControls folder to my project folder and add the MapPrintingControls project into my project? When I did this, but I cannot find the MapPrintingControls.dll from the "add reference"...there seems no option like this.
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Can I just copy the MapPrintingControls folder to my project folder and add the MapPrintingControls project into my project?

Yes, you can. In this case, in the add reference dialog box, you have to use the 'Projects' option.
0 Kudos
DanDong
Deactivated User
Yes, you can. In this case, in the add reference dialog box, you have to use the 'Projects' option.


Thank you! I added this reference successfully 🙂

But if I dont add this assembly: xmlns:userControls="clr-namespace:MapPrinting.UserControls"
I cannot use the userControls:windowPanel which represents the MapPrinter Dialog Panel.
0 Kudos
ElizabethPianta
Deactivated User
Hi Dominique! Thanks for providing the SL4 PDF print functionality sample. It looks to be most useful to a widespread audience. And I have enjoyed some success in accessing it through my web mapping application. I have successfully compiled the code you provided. Following your instructions in the README file I was able to include a reference to the 'MapPrintingControls.dll' from the build and add some assembly references to get it up and running in my application. The end-user was quite pleased. And, of course, asked for more.

I have read through the forum threads to find out how to customize the code to include a title and a legend on the map printout. I was able to add user-defined address and title fields to the map printout by customizing your code in the 'MapPrinterDialog.theme.xaml' file and including additional textbox entries on the dialog panel. And rebuilding the code in your sample.

I am also attempting to add a legend to the map printout by customizing the code in the 'MapPrinter.theme.xaml' file. However, I am not having much success. When I attempt to add the legend tags <esri:Legend></esri:Legend> the intellisense complains that the control is not recognized and to check my assembly references. I added the following to the top of the 'MapPrinter.theme.xaml' file. The 'ESRI.ArcGIS.Client.Toolkit' has been added to the references in your project. This may be a no-brainer but I have to admit I am stumped as to what the problem is. Am I doing this in the wrong place?

Now I may be misunderstanding how to implement the addition of a legend on the PDF map printout, so please inform me if I am not attempting to do this the right way. And do please let me know how to go about doing this correctly. I have no problem implementing a dynamic legend in my web mapping application.

The platform I am running is SL4 with ArcGIS API for Microsoft Silverlight/WPF v2.1 on the client-side, and ArcGIS 10 w/SP1 on the server side to read the legend dynamically in my application. The application I am calling your 'MapPrintingControls.dll' from is developed using VB.NET and not C#. Since this is a dll this should not effect anything. But it means I am unable to include the 'MapControls' folder within my VB project.

What am I doing wrong? Your help in regard to this matter is much appreciated.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hi Elizabeth,

Thanks for your nice comments about the sample.

Concerning the legend, it's for sure possible to add a legend to the map printout.
It's not mandatory to change the MapPrintingControls project and the MapPrinter.Theme.xaml file. You can do it in your application project by defining a new style for the MapPrinter.

Did you look at the sample, there is a 'WithLegend' map printer style defined in MainPage.xaml?

That being said if <esri/legend> is not recognized, it looks more like a project reference issue.
Note that the legend control has been introduced with version 2.1 of the API and is  not available with previous versions.

Which ArcGIS SL version are you using?
0 Kudos
ElizabethPianta
Deactivated User
Good Morning Dominique!
Thank you for your response. I am remote logging into another pc which is running the development environment which includes Silverlight 4, MS Visual Studio 2010, and ArcGIS API for Microsoft Silverlight/WPF v2.1 because I do not have all of these platform requirements installed on my pc. However, I do not believe this is the problem because I am able to create a dynamic legend in a small test application in this development environment. The dynamic legend displays the symbology swatches as expected.

I included your MapPrinter dll in this simple test application, which pops up the MapPrinter dialog box when the 'Print PDF' button is selected. I am able to print out a map from the MapPrinter dialog box.

Thank you for your suggestion to review the code in your sample's MainPage.xaml file. If I am understanding the sample code correctly, it looks like the following code in my project application's MainPage.xaml file defaults to use the "Basic" style for the MapPrinter control that you created since I have not defined a style:

         <userControls:WindowPanel x:Name="PrintDialogPanel" ContentTitle="PDF Printing"           Collapsible="False" Closable="True" Minimized="False" Visibility="Collapsed">
            <controls:MapPrinterDialog Height="410" Width="340">
                <controls:MapPrinter x:Name="mapPrinter" Map="{Binding ElementName=MyMap}" />
            </controls:MapPrinterDialog>
         </userControls:WindowPanel>

How do I reference the "WithLegend" style in my code above so that the default style "Basic" is not used?  I would indeed like to include a legend on the map printout.

Thank you for your guidance and help on this matter.
0 Kudos