Potential Solutions for Implementing Reporting

There are a number of ways to implement reporting in Silverlight applications, each with its pros and cons, including the following:

  • Using Silverlight printing functionality
  • Generating a PDF
  • Generating HTML
  • Generating Office documents

The following sections explore each of the preceding possibilities.

Using Silverlight's Printing Functionality

The introduction of printing in Silverlight 4 allowed you to print an object hierarchy, such as what's displayed on a screen. Unfortunately, it only supported sending the output to the printer as a bitmap, rather than using a vector-based output, resulting in low print quality and large files being sent to the printer. This made it suitable only for printing screens, instead of reports.

Silverlight 5 has fixed this limitation by providing support for vector printing, making Silverlight's native printing capability much more viable for printing reports. That said, Silverlight 5's printing support is still somewhat primitive, requiring you to manually handle the entire printing process, including page breaks and so on. If you want to use Silverlight's printing functionality to print reports, you are probably best off using a third-party report viewer, which we'll look at in the “Third-Party Report Viewers” section.

images Note Pete Brown and David Poll have a simple report writer project on CodePlex that you may want to look into if you want to generate reports using Silverlight's built-in print functionality. This project includes handling page headers and footers, page numbering, pagination, and the report footer, among other features. You can get more information and download it at http://silverlightreporting.codeplex.com.

Generating a PDF

You are probably used to generating reports using a reporting tool, such as the local report designer in Visual Studio or Crystal Reports, and then displaying the report in the provided viewers. Unfortunately, neither of these tools has a viewer for Silverlight, but an alternative solution is to output the reports they generate to a PDF file, stream that through to the client, and display the PDF using one of the following techniques:

  • In a new window
  • In an IFrame overlaid on the application, when running inside the browser
  • In a WebBrowser control to display the PDF, when running outside the browser or inside the browser with elevated trust

When the PDF is displayed in the window, it will be displayed in the Adobe Reader plug-in. This provides the ability to print the PDF, enabling you to both display and print the report in the application, provided that the user has the Adobe Reader plug-in installed.

images Note Generating a PDF was the preferred solution when printing was not available in Silverlight, and it tends to still provide an excellent solution for printing complex reports.

Generating HTML

You can use the same techniques for displaying plain HTML in a Silverlight application as described for displaying a PDF; the HTML can then be printed by a browser. If you generate your reports as HTML, this provides another potential solution for printing reports.

Generating Office Documents

Once again, you can use the same techniques for displaying Word and Excel documents in a Silverlight application as described for displaying a PDF. These documents will be loaded in their corresponding viewers within the IFrame/WebBrowser control, which will provide the ability to print the documents. If you have your reports generating as Word or Excel documents, this provides another potential solution for printing reports.

images Note One of the advantages of generating Word and Excel documents is that it gives the user the opportunity to modify the generated report before printing it. Most users have Word installed, and when using the Open XML standard (DOCX) format introduced in Microsoft Word 2007 (with the Office Compatibility Pack downloadable from Microsoft to open these files in earlier versions of Word), it can be easy to populate a Word document template with data on the server without requiring messy automation. In some cases, it may be better to move to a reporting engine that can generate DOC or DOCX files as their output—for example, scaling up to SQL Server Reporting Services.

Third-Party Report Viewers

A number of third-party reporting solutions have viewers for Silverlight. Let's take a look at some of them.

Perpetuum Software's Report Sharp-Shooter for Silverlight

Perpetuum Software (www.perpetuumsoft.com) has a Silverlight viewer control named Silverlight Viewer for Reporting Services, which displays reports generated by SQL Server Reporting Services directly within Silverlight and enables you to print them. If you use SQL Server Reporting Services to generate reports, this may be a viable option. Perpetuum also has its own report designer/engine with a Silverlight Viewer control called Report Sharp-Shooter for Silverlight that you may want to use.

At the time of this writing, a single license for Perpetuum's Silverlight Viewer for Reporting Services is $500.

Telerik Reporting

Telerik (www.telerik.com) has a Silverlight report viewer for its Telerik Reporting, which enables you to view and print reports generated by its reporting engine in your Silverlight application.

At the time of this writing, a single license for Telerik Reporting is $399, or $599 with source code and major version updates.

DevExpress XtraReports Suite

DevExpress (www.devexpress.com) has a Silverlight report viewer named DocumentPreview, for its XtraReports Suite; it enables you to view and print reports generated by its reporting engine in your Silverlight application.

At the time of this writing, a single license for DevExpress's XtraReports Suite is $349.99, or $499.99 with source code.

Infragistics NetAdvantage Reporting

Infragistics (www.infragistics.com) has a Silverlight report viewer as part of its NetAdvantage Reporting product; it enables you to view and print reports generated by its reporting engine in your Silverlight application.

At the time of this writing, a single license for Infragistics NetAdvantage Reporting is $995 and includes full source code.

ComponentOne C1ReportViewer

ComponentOne (www.componentone.com) has a Silverlight report viewer named C1ReportViewer as part of its Studio for Silverlight. This viewer enables you to view and print reports generated by various reporting engines in your Silverlight application.

At the time of this writing, a single license for ComponentOne's Studio for Silverlight starts at $895.

Stimulsoft Reports.Silverlight and Reports Designer.Silverlight

Stimulsoft (www.stimulsoft.com) has a Silverlight report viewer, which enables you to view and print reports generated by its reporting engine in your Silverlight application. It also has a Silverlight report designer, which enables your users to design a report within your application.

At the time of this writing, a single license for Stimulsoft's Reports.Silverlight is $599.95, or $999.95 with source code. Stimulsoft's Reports Designer.Silverlight is $299.95, or $499.95 with source code.

MindFusion.Reporting

MindFusion (www.mindfusion.eu) has a Silverlight report viewer as part of its Silverlight Pack, which enables you to view and print reports. At the time of this writing, a single license for MindFusion's Silverlight Pack is $300, or $650 with source code.

GrapeCity ActiveReports

GrapeCity (www.pcpowertools.com) has a Silverlight report viewer as part of the a generated by the ActiveReports reporting engine.

At the time of this writing, a single license for the Professional edition of ActiveReports is $1599, or $2159 with maintenance.

First Floor Software's Document Toolkit + Aspose Converter

First Floor Software (www.firstfloorsoftware.com) has a Document Toolkit that enables XML Paper Specification (XPS) documents to be displayed in a Silverlight application. XPS is a XAML-based document format from Microsoft, which makes it perfect for displaying documents such as reports within a Silverlight application. Therefore, if you can output your reports to XPS, you can display them in your application using the Document Toolkit.

To create an XPS file, you can simply print a document to the Microsoft XPS Document Writer. XPS documents are ZIP files, and you can inspect their contents by changing their extension to .zip and expanding them. You'll note that the core document contents are stored as XAML, so you could potentially harness this to generate reports on the server using a template XPS document, populating it on the fly when a user requests a report, and serving it up to the Silverlight client for display. This is a very crude solution, but it would work. For example, you could parse these files (such as using regular expressions to replace predefined tokens in the document with actual values), zip up the document (with an .xps extension), and serve this to the Silverlight client for display.

A somewhat better solution is to automatically generate the XPS document, which you can do using Aspose.Words for .NET (another commercial product, available at www.aspose.com). You can find an example of implementing this in the Document Toolkit Extensions project on CodePlex at http://documenttoolkit.codeplex.com.

images Note Some sample code is available in a number of places on the Internet that demonstrates displaying XPS documents in Silverlight (with source code) but is incomplete and done purely as proof of concept. You may want to look at these too, but the Document Toolkit is currently the only full-fledged XPS viewer available for Silverlight without creating your own. At the time of this writing, there is experimental support for displaying PDFs in addition to XPS documents.

At the time of this writing, a single license for First Floor Software's Document Toolkit is €299. A single license for Aspose.Words for .NET starts at $999.

Office Integration Using COM

In Chapter 16, we will discuss running the application outside the browser with elevated trust. This scenario gives you access to COM, through which you can interact with the various Office applications installed on the user's machine (Word, Excel, and so on).

You can use this technique to enable your Silverlight application to generate a report directly in Word or Excel, which the user can then print. We won't be looking at this option in this chapter, but Beth Massi has an in-depth blog post demonstrating how you can use the technique here: http://blogs.msdn.com/b/bethmassi/archive/2010/09/10/using-microsoft-word-to-create-reports-for-lightswitch-or-silverlight.aspx. Although the blog post is geared toward generating reports in Word using LightSwitch, you should be able to easily adapt it to Silverlight.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset