drawkcaB | Backward Compatible logo

rants and tips about software

Problem with wxWebConnect and printing

I started using wxWebConnect by Kirix in one of my applications and
ran into problems with printing. When using the latest XULRunner
1.9.2.10 the Print() function would not work at all. Looking into
wxWebConnect code, it seems that it did not manage to get either of
settings for XULRunner 1.8 or 1.9. First I thought about using 1.8,
but had some problems downloading it and I tried 1.9.1.13 instead. To
my surprise, this one works fine. It uses the engine from Firefox 3 so
I’m happy now.

The second issue is inability to control all the aspects of printing.
One of the problems is that selecting the “only the selected frame”
option still prints the whole page. I have a many pages with HTML
frames and currently I advise users to open the desired frame in a new
window before printing it out. If anyone knows how to solve this…
please say so.

Next issue is getting landscape print to work. There’s a TODO in Kirix
code, but I managed to fix it with just a few lines a code. I
understand that this might be an ugly hack, but I don’t really care
that much as long as it works. As I understand, my code doesn’t
actually switch to landscape print, but rather sets a wider page for
regular portrait print. Anyway, there the code. Just apply this to
OnPageSetup function:

- page_width = paper_size.GetWidth()/25.4; 
- page_height = paper_size.GetHeight()/25.4;
+ int orientation = data.GetPrintData().GetOrientation();
+ if (orientation == wxLANDSCAPE)
+ {
+ page_width = paper_size.GetHeight()/25.4;
+ page_height = paper_size.GetWidth()/25.4;
+ }
+ else
+ {
+ page_width = paper_size.GetWidth()/25.4;
+ page_height = paper_size.GetHeight()/25.4;
+ }

Finally, Firefox prints the default footer and header that includes
page URL, which I want to avoid. In fact, I removed everything except
the page number. I did not bother to look into coding this, as it
seemed too much work. Instead I ran about:config in my regular Firefox
installation and searched to print related settings. It was rather
easy to find header and footer. Luckily, you can change these from
code:

+ webprefs.SetStringPref( wxT("print.print_footercenter"), wxT("&PT")); 
+ webprefs.SetStringPref( wxT("print.print_footerleft"), wxT(""));
+ webprefs.SetStringPref( wxT("print.print_footerright"), wxT(""));
+ webprefs.SetStringPref( wxT("print.print_headercenter"), wxT(""));
+ webprefs.SetStringPref( wxT("print.print_headerleft"), wxT(""));
+ webprefs.SetStringPref( wxT("print.print_headerright"), wxT(""));
Milan Babuškov, 2010-10-17
Copyright © Milan Babu┼íkov 2006-2014