.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Print Document in Silverlight 4.0

Posted By:Dhananjay Kumar       Posted Date: January 07, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

Print Document in Silverlight 4.0


This article will introduce New Printing support in Silverlight 4.0.


Silverlight 4.0 add support to enable business application development.  Printing support allows developer to print the Silverlight application itself.  Printing support helps

  1. Formatting the content of the Printing.
  2. Specifying the content of the Printing.
  3. Choosing the Printer.
How Printing support works?

While using the Printing support classes, eventually Silverlight application open the Printing Dialog box.

What is new in Silverlight 4.0 for printing support?

Answer is PrintDocument class. This class provides events and function to achieve Printing in Silverlight application. 

PrintDocument class
  1. This class is inside namespace System.Windows.Printing.
  2. There are three events to handles printing. They are EndPrint , StartPrint , PrintPage.
  3. There is one method called Print() to do the print operation.  This method takes no input parameter.
  4. There is a property DocumentName .
How to use this class?
  1. Create instance of PrintDocument class.
  2. Specify the content to print.
  3. Write code to handle the PagePrint event.
  4. Entire Silverlight control can be printed by setting PageVisual to layout.
  5. Portion of Silverlight application can be printed by setting the pagevisual tospecific control.
Diving to some example

I have a
  1. Stack Panel inside a Grid
  2. Inside Stack Panel there is one button and a text box.


Now I need to, print the text Box
  1. Create instance of PrintDocument class.
  2. Handling PrintPage event
  3. Inside the event setting PageVisual to name of the text box.
  4. Calling the Print() method in last.
  5. If you want to print the entire application, just set PageVisual to any layout like stack or Grid. In this case for stack  PageVisual would be set to stkPanel.
private void mybutton_Click(object sender, RoutedEventArgs e) 
  PrintDocument prt = new PrintDocument(); 
  prt.PrintPage +=(s,args) => 
  args.PageVisual = txtBlcok; 



On clicking of Print Button, Here you could select you Print options. 



In this article, I gave a basic introduction of Printing Support in Silverlight 4.0.

Thanks for reading.
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend