Implementing the printing API
You've just created the perfect LOB application. Everything works great and users are happy. After a while, a few of them come to you with a request that seems quite trivial—they need to print forms and pages off your application. As trivial as this request sounds, up until Silverlight 3 this would have been impossible. Silverlight 3 introduced the WriteableBitmap
class, which allows you to save any element in your application as a bitmap and then print it. Silverlight 4, however, was the first Silverlight release to introduce a real solution to the printing problem, known as the printing API.
The entire printing process in Silverlight relies on an object called PrintDocument
. This object contains three events that cover the entire lifespan of the printing process—BeginPrint
, PrintPage
, and EndPrint
.
The BeginPrint
event is raised as soon as the Print
method gets called on the PrintDocument
object. Then, for each page that needs to be printed, PrintDocument...