Monthly Archives: May 2010

Printing in Silverlight: Printing Charts and Auto Scaling

Printing support has been introduced in Silverlight 4. This means that any part of the visual tree can be printed with some simple API calls (see the Printing Basics section on my Advanced Printing in Silverlight post). This post provides an example to print charts and looks at how elements can be auto scaled to fit the page size.

Printing a chart

There are lots of examples on blogs demonstrating printing on simple elements. However I wanted to test how the printing functionality performs when working with charts.

I chose to use the most widespread (and free) charting component, the Silverlight Toolkit. In my example I’ve created four charts and added printing support to all of them like this:

Chart chartToPrint; // The element to be printed
PrintDocument doc = new PrintDocument(); // Create the PrintDocument  object that will do the printing
doc.PrintPage += (s, args) =>
{
  // Set the chart that needs to be printed.
  // As soon as this is set, printing starts
  args.PageVisual = chartToPrint;
}

In the example the whole page can be printed as well by clicking on the Print whole page button. In this case the LayoutRoot element is passed as the PageVisual. Test the example yourself:
Read More…

 Scroll to top