views:

2002

answers:

3

I need to export a SL DataGrid to html so my users can then print it. Can someone put me in the right direction?

Upate: After reading Rob's answer I am changing my question. Instead of Silverlight Grid to HTML, I now just want to export it to PDF. Has anyone used any 3rd party PDF generators with Silverlight?

+1  A: 

HTML is a bad choice for printing for several reasons which are well documented on this site so I won't get into them.

I would suggest that you export to PDF rather than attempt to go with the HTML route. For Exporting to PDF there are a number of good .Net tools available. Other options include exporting your grid to a spreadsheet program like Excel, Spreadsheet Gear, or OpenOffice Calc which will offer additional functionality.

Rob Allen
Rob,I agree html isn't the best choice and pdf would be better. What I am looking for is a 3rd party pdf generator that I could export the grid and not have to build the pdf from the datasource of the grid. I will if I have to but I'm looking for the lazy solution first.
Kyle
pop that comment back into your original request and you will get more relevant responses. I haven't done that directly.
Rob Allen
+1  A: 

This might be a stretch, but what about exporting the Silverlight Xaml to XPS and returning an XPS document to the user (which is printable). You can download a free XPS viewer here. I've done this in the past with WPF and XBAPs, so I imagine you could do this on the server side and let the user download the XPS document.

Bryant
+1  A: 

If you want to generate PDF or XPS in Silverlight you would have to round-trip back to the server. There are multiple frameworks and tools available to do PDF generation in .NET.

However, I wouldn't abandon the idea of generating HTML to do printing in Silverlight 2. I think this is an excellent idea, and I don't consider web printing broken. HTML with CSS print style sheets can be really usefull.

I recently did a blog post describing how to use the ASP.NET AJAX 4.0 Client Templates to generate HTML on the client using Silverlight 2. It shouldn't be to hard to write a piece of C# code to convert any data grid to a HTML table.

However, if you know what kind of objects you're displaying in the data grid you could simply generate the HTML your self based on your object structure.

You have multiple options for generating HTML in Silverlight:

You pass HTML back to the browser using the HTML Bridge (google for it for more information).

You should also check out my blog post for a comprehensive overview of printing options in Silverlight.

Jonas Follesø