Board index » cppbuilder » WebBrowser: Printing from an inactive form

WebBrowser: Printing from an inactive form


2005-04-26 01:03:02 AM
cppbuilder102
Hello,
I have written a (local) HTTP-Server which generates a HTML-page after getting
the needed informations from a Standard-Browser (Netscape or IE) and displays
that generated HTML-page in a WebBrowser-Component (on the HTTP-Server-Form).
Now I want to print that page, controlled by the Standard-Browser (JavaScript).
When I click the print-button on the form, all is working as expected, but when
I trigger printing with the Standard-Browser printing doesn't work. I assume the
problem is that my HTTP-Server-Form isn't active. Is there any solution for that
problem? Of course the HTTP-Server must work in the background and is later hidden.
Thanks and kind regards,
Udo
 
 

Re:WebBrowser: Printing from an inactive form

"Udo Weik" < XXXX@XXXXX.COM >wrote in message
Quote
When I click the print-button on the form, all is working as expected,
but when I trigger printing with the Standard-Browser printing doesn't
work. I assume the problem is that my HTTP-Server-Form isn't active.
No. Printing has nothing to do with the server at all. Once a browser
downloads a page, the browser has all of the data it needs to send the page
to the printer. The server is not involved at all, other than for the
initial download.
Gambit
 

Re:WebBrowser: Printing from an inactive form

Hello Remy,
Quote
>When I click the print-button on the form, all is working as expected,
>but when I trigger printing with the Standard-Browser printing doesn't
>work. I assume the problem is that my HTTP-Server-Form isn't active.

No. Printing has nothing to do with the server at all. Once a browser
downloads a page, the browser has all of the data it needs to send the page
to the printer. The server is not involved at all, other than for the
initial download.
thanks for your fast answer. I must be more precise.
I have written a HTTP-Server, with TIdHttpServer and a TWebBrowser
(created with an Libary Import). This HTTP-Server generates a HTTP-
Page which is displayed in the TWebBrowser. Now I want to print that
page:
if ( cbHTML_PrintDirect->Checked )
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT, Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER ) ;
else
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT, Shdocvw_tlb::OLECMDEXECOPT_PROMPTUSER ) ;
When I call that code-snippet via a button on my HTTP-Server-Form, all is
working as expected. But when I trigger printing from my (client) HTML-Page,
printing doesn't work. I assume that the problem is that my HTTP-Server-Form
is not active in the second case.
Greetings
Udo
 

{smallsort}

Re:WebBrowser: Printing from an inactive form

"Udo Weik" < XXXX@XXXXX.COM >wrote in message
Quote
I have written a HTTP-Server, with TIdHttpServer and a TWebBrowser
(created with an Libary Import).
Are you using the TWebBrowser in the same executable as the TIdHTTPServer?
Quote
When I call that code-snippet via a button on my HTTP-Server-Form,
all is working as expected. But when I trigger printing from my (client)
HTML-Page, printing doesn't work.
How are you initiating the printing in that case?
Quote
I assume that the problem is that my HTTP-Server-Form is not active
in the second case.
You assume incorrectly. As I already mentioned, the HTTP server is not
involved in printing at all.
Gambit
 

Re:WebBrowser: Printing from an inactive form

Hello Remy,
Quote
>I have written a HTTP-Server, with TIdHttpServer and a TWebBrowser
>(created with an Libary Import).

Are you using the TWebBrowser in the same executable as the TIdHTTPServer?
Yes. The TWebBrowser works like a printer canvas. It should later print
the dynamically generated page, triggered by my standard HTML-Page in the
browser via the HTTP-Server.
Why that approach: I want to print that dynamically generated page without
a print-dialog. I could load that page in a hidden frame on my standard HTML-
page, but printing without dialog is not possible with IE6 due to security
reasons. And the frame must have the focus before printing, so I'm not sure
whether I can hide it.
Quote
>When I call that code-snippet via a button on my HTTP-Server-Form,
>all is working as expected. But when I trigger printing from my (client)
>HTML-Page, printing doesn't work.

How are you initiating the printing in that case?
I use that "forbidden" way with a dummy image request. The OnCommandGet-
event from my HTTP-Server is triggered, that works. BUT that HTTP-Server-
Form is not active in that case and I assume that's the problem.
Quote
>I assume that the problem is that my HTTP-Server-Form is not active
>in the second case.

You assume incorrectly. As I already mentioned, the HTTP server is not
involved in printing at all.
BUT when my HTTP-Server-Form is active and I press the print button (on
that form), all works as expected - either with print-dialog or without.
Greetings
Udo
 

Re:WebBrowser: Printing from an inactive form

"Udo Weik" < XXXX@XXXXX.COM >wrote in message
Quote
>How are you initiating the printing in that case?

I use that "forbidden" way with a dummy image request.
I do not understand what you are referring to. You have not explained the
"dummy request" yet. Please explain.
Quote
BUT when my HTTP-Server-Form is active and I press the print
button (on that form), all works as expected - either with print-dialog
or without.
Please show your actual code.
Gambit
 

Re:WebBrowser: Printing from an inactive form

Hello Remy,
Quote
"Udo Weik" < XXXX@XXXXX.COM >wrote in message
news:426e65d3$ XXXX@XXXXX.COM ...

>>How are you initiating the printing in that case?
>
>I use that "forbidden" way with a dummy image request.

I do not understand what you are referring to. You have not explained the
"dummy request" yet. Please explain.
That's the same problem as mentioned in newsgroup
atozedsoftware.indy.protocol.http
thread "Getting Image via JavaScript from TIdHTTPServer/Netscape":
In more detail, I'm calling the following JS-Code:
function cm_DummyRequest()
{
var sLink ;
var dtNow = new Date() ;
sLink = "127.0.0.1/Dummy_" + dtNow.getTime() + "?ACTION=PRINT" ;
imgDummy = new Image() ;
imgDummy.src = sLink ;
}
The aim is that my HTTP-Server prints the just generated page via the TWebBrowser.
Quote
>BUT when my HTTP-Server-Form is active and I press the print
>button (on that form), all works as expected - either with print-dialog
>or without.

Please show your actual code.
Print-Button on that HTTP-Server-Form:
--------------------------------------
if ( cbHTML_PrintDirect->Checked )
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT, Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER ) ;
else
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT, Shdocvw_tlb::OLECMDEXECOPT_PROMPTUSER ) ;
Snippet from OnCommandGet-Event (TIdHTTPServer), again HTTP-Server-Form:
------------------------------------------------------------------------
sFilePrefix = "/Dummy" ;
if ( ARequestInfo->Document.SubString( 1, sFilePrefix.Length() ) == "/Dummy" )
{
if ( cbHTML_PrintDirect->Checked )
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT, Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER ) ;
else
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT, Shdocvw_tlb::OLECMDEXECOPT_PROMPTUSER ) ;
}
ieaxAPP_ is the TWebBrowser.
Don't know I ever mentioned this - just want to print a frame without print-dialog with IE 6.
And the content of that frame must be valid, remember the caching-problems.
Thanks, Remy, for your time.
Udo
 

Re:WebBrowser: Printing from an inactive form

"Udo Weik" < XXXX@XXXXX.COM >wrote in message
Quote
That's the same problem as mentioned in newsgroup
atozedsoftware.indy.protocol.http
thread "Getting Image via JavaScript from TIdHTTPServer/Netscape":
We are in the Borland groups here, not the Indy groups. Next time you post
a discussion across servers, make sure people in both servers know what you
are talking about.
Quote
In more detail, I'm calling the following JS-Code:
Why are you using a dummy request to begin with? Like I said before, it
looks like you are abusing the HTTP protocol to begin with.
Quote
The aim is that my HTTP-Server prints the just generated page
via the TWebBrowser.
Why, though? Since you are running JS code inside a browser to begin with,
why not just have the browser print directly? Wny do you have to involve
the server at all? You are over-complicating things for yourself.
Quote
sFilePrefix = "/Dummy" ;
if ( ARequestInfo->Document.SubString( 1, sFilePrefix.Length() ) ==
"/Dummy" )
{
if ( cbHTML_PrintDirect->Checked )
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT,
Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER ) ;
else
ieaxAPP_->ExecWB( Shdocvw_tlb::OLECMDID_PRINT,
Shdocvw_tlb::OLECMDEXECOPT_PROMPTUSER ) ;
}
Since you are not checking the return value of ExecWB() at all, I will bet
you that it is actually failing with an error that you are ignoring, most
likely RPC_E_WRONG_THREAD since TIdHTTPServer is multithreaded and you are
trying to access an ActiveX interface in a different thread than the one
that owns the TWebBrowser instance.
Gambit