views:

400

answers:

2

I've got a small program that displays third-party generated HTML pages. It's really just a wrapper around a locked-down TWebBrowser component (which is just an IE wrapper, I believe).

The client wants to print these pages now too - but the TWebBrowser print method doesn't render all of the CSS. For instance, where the client uses blocks of background colour, I just get the background colour. You can actually see this on some websites when you get IE to print the pages and some of the CSS-type formatting disappears.

I originally convinced myself (stupidly) that the problem was because the CSS was an external reference, but after I'd made the CSS internal to the .HTML file the problem remained.

Is there a component or technique I can use to get printed output that includes this CSS formatting? I wondered about trying to turn the browser page into a PDF first (that would have other advantages for me too, later) but I don't see any obvious way of doing that either.

I guess really I'm saying - printed output from IE sucks, is there a way of getting a better approximation of what you see on-screen? :-)

edit: Okay, moved this on now. I can persuade the printed output to include the CSS colour elements, thanks to Will and Onnodb's suggestions - my sample page prints okay, and given that the user understands the significance of the registry setting approach, he's happy to go that way with it (it's going to be used on at most a half-dozen desktops in a locked-down corporate-type office).

My problem now (which might itself become a new S/O post) is that there's something in their HTML/CSS that is killing IE. Firefox is happy to print it all out just fine (and so does Safari), but IE 7 and 8 will both show a print-preview of the pages but die during 'real' printing.

Given that replacing TWebBrowser with some kind of TGeckoBrowser(!) is probably more trouble than it's worth (and might not fly with the client), I'll have to try and figure out what bit of the (nasty, convoluted) formatting code is causing the problem. There are a multitude of DIVs in there with a mixture of relative and absolute positions... :-)

+5  A: 

Are you linking the stylesheets with media="screen,print" in their link/style tags? Also with printing you need to bear in mind things like their printer settings: does a user want to let you print out page background colours? Have you defined the font face specifically or has the user set a preferred printing font of their own in the browser properties?

It's generally a good idea to write a totally separate stylesheet for printing purposes, since serif fonts like Georgia are easier to read on paper, and the font size may need changing. Images might want to be hidden or scaled down too.

Will Morgan
Hmmm, all good questions! I hadn't changed the stylesheet tags but will look at trying that first-off. The user definitely wants the print-out to accurately reflect their on-screen CSS, so colour and font-faces are to be kept the same (*sigh*!!) Good point about the font-sizes though - many thanks!
robsoft
+2  A: 

AFAIK, IE has a setting on its "print settings" dialog that allows the user to choose whether she wants to print background colours or not. You'd have to change that setting, either by letting the user do so herself, or by changing the registry programmatically. Either way, there doesn't seem to be a way to change this setting on a per-document basis.

onnodb
Though you have a point, having a program edit a user's registry to change settings that affect accessibility isn't a good idea.
Will Morgan
@Will: Sure, I completely agree with you on that :) Also depends on the app and the client, though.
onnodb
Yes, if the app is built out of Gator software and the client is an unsuspecting user with no antivirus software :)
Will Morgan
Thanks Onnodb, that's helpful. In this particular case I can 'get away' with my program storing the current setting, changing it (it necessary), printing, and changing it back. Though Will's points would definitely stand if this was going anywhere other than a closed, controlled environment.
robsoft