The mystery of landscape printing

From: Andrew Mayo (ajmayo_at_my-deja.com)
Date: 07/21/04


Date: 21 Jul 2004 09:06:42 -0700

As Microsoft say somewhere 'So you want to have the browser handle
printing, and you're willing to make a Faustian bargain with the
browser to do it...' and they are SO right.

However, I have pretty much tamed the web browser control now, after
some horrendous experiences (it's multithreaded and doesn't always
behave in the VB6 environment as you would expect. Bug of the week is
this...

wbrowser.navigate <some_url>
set hdoc=wbrowser.document 'aarrrggh, bad bug coming up
do until hdoc.readystate="complete"
     doevents
loop

where the above piece of code can result in hdoc (defined as
HTMLDocument) intermittently ending up with the PREVIOUSLY loaded
document in the browser, unless you yield BEFORE making the assignment
(sigh!)

[mysterious, I have to say, since once readystate transitions to
complete, reassigning will get you the newly-loaded document as well,
but clearly there's a race condition going on here]

But I digress....

The last mystery now is how you might coerce the browser into printing
landscape. Without pissing around with print templates.

There's one article that implies that there's a registry key for this.
That appears to be untrue. Where the print setup dialogue stores the
portrait/landscape setting is a mystery which even a thorough rogering
with sysinternals regmon didn't reveal. (i.e it ain't going up the
registry, nohow)

So at this stage the other cunning tricks e.g munging margins by
changing the registry, don't work for portrait/landscape.

I know that one commercial product does this by bringing up the
dialogue and poking at it with a stick, but surely to heaven there's
an easier way. Any experts on this one?

PS: other bad browser bugs.

1. A VB application may GPF on termination because of messages
dispatched on one thread being received by the browser control during
program termination. Cure - use the Windows API to terminate the
application as the last line of code (don't call that in the dev.
environment, of course!)

2. Checking for document complete can be problematic. Sometimes
readystate transitions to "complete" early. Trapping the browser event
and setting a boolean on this, combined with a readystate check, often
helps.

3. A VB form with an embedded browser control with contenteditable
fields won't get the focus put back on the correct field when the form
itself loses and regains focus. The cure involves using a
messageblaster and trapping an undocumented windows message to get a
reliable hook for resetting focus.

4. Certain keys are trapped by the browser and (mis)handled e.g F5.
You can use a browser helper object to fix this (MS sample code) but
it will need modification if you want to use the keystrokes in your VB
code otherwise the accelerators will be silently eaten.



Relevant Pages

  • Re: Local Printing with IE
    ... Paul T. ... works fine with my own code, but the browser never even does that. ... but installing serial port sniffer between printer and your ... printing support component to your platform in PB? ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Implementing print functionality in ASP.NET web application
    ... the browser, and the browser is designed to prevent any malicious code from ... Run a search over at www.dynamicdrive.com for some JavaScript print ... There must be some way to get some printing done from a web page. ... page from which I entered my question has a button saying 'Print Post'. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Protecting XML File While Displayed In Browser
    ... If you're sending data to the user in IE, there's nothing I'm aware of that will protect it before printing. ... Assuming you had some way to protect the data all the way to the printer, once its been printed out you have a whole new set of problems. ... Protecting XML File While Displayed In Browser ...
    (microsoft.public.dotnet.security)
  • Re: Local Printing with IE
    ... Anyway, a full debug build with the browser in it has been, useless. ... do you use the same serial port parameters as IE printing does? ... Windows CE control panel --> Printers to the same serial port? ...
    (microsoft.public.windowsce.platbuilder)
  • Re: [opensuse] RFR: Printing From Browsers
    ... Subject: RFR: Printing From Browsers ... I never heard of a browser that prints very well. ... The obvious reason is html just isn't designed for that. ... But that very statement about flowing to fit any window ...
    (SuSE)