Chad Osgood's Blog

The manifest of a geek microcosm

Reporting with XML/XSLT and printing with CSS

In a few of my Windows Forms applications that require reporting facilities I employ a typical XML/XSLT method.  I emit XML from my application and then use various XSLT stylesheets to translate said XML into HTML for each required report.  This works well when client deployment is decentralized with no central repository to persist data.  To display the report I usually interop with shdocvw.dll and put an instance of the control in a form.  This gives the client the perception, albeit superficial one, of an integral reporting facility.

There have been times when I needed to display a more verbose report during preview but a more terse report on print.  To facilitate this I would employ what Martin Fowler calls a Two Step View web presentation pattern in his book Patterns of Enterprise Application Architecture by applying multiple XSLT stylesheets: one for preview, and one for print.  Brad Wilson speaks of using CSS for printing which I could more succinctly employ for my Two Step View pattern as opposed to having to deal with multiple XSLT stylesheet translations.

Cool!

Comments

Ben Richardson said:

That sounds like a nice way to go about creating reports. One quick question, when printing, do you get the page title at the top and url at the bottom, like you do when printing in IE?
# February 11, 2003 8:53 PM

Chad Osgood said:

No. You can remove/alter the header/footer via the header and footer registry keys under HKCU\software\microsoft\internet explorer\pagesetup. I haven't delved far enough into shdocvw.dll's typelib to see if there is a means of changing this programatically. Alternatively, you could save and alter the keys before print and restore them after. I plan on doing the latter unless I can find a means to do it programatically.
# February 11, 2003 9:25 PM

Ben Richardson said:

The other problem I have run into using HTML for my reports is that I can't specify where a page starts/end, so when they print the report, a table can go over a page when it would be preferable if it didn't start until the next page. There are also instances where I need to display the report header at the top of each page, which I can't do in multi-page HTML reports.

So I have been using Crystal Reports for my Win Forms reports, which solve the problems above, but also introduces new hassles, such as having to store images as BOLBS in the database if you want to include them in the report.
# February 11, 2003 10:09 PM

Chad Osgood said:

You can control where the page breaks when printing in IE with a few CSS attributes. Have a look-see at page-break-before. I usually set it to always for an HTML break:

br.pagebreak
{
page-break-before: always
}

It works quite well. I am not certain if Netscape/Others have such an attribute, but since I'm interoping with shdocvw.dll, I'm enforcing IE anyway.
# February 12, 2003 7:48 AM

Steve Tapajna said:

Any easy way to force IE to print landscape for wide reports?

Steve
# June 3, 2003 5:50 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)