Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Poss. to print from TWebBrowser ? 2

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
0
0
GB
hi

Is it possible to print the contents of a TWebBrowser component ?

thanks
lou
 
Lou,

Yes, it is. Consider, for example:

Code:
   webBrowser1.execWB( OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT );

execWB provides a way to send several commands to the WebBrowser object using the IOLETarget interface. For full details, please see the Help file topic on WBEXEC, as well as the appropriate Microsoft documentation.

For starts, here are two links (that will likely be mangled. sorry):



For more information, you might search msdn.microsoft.com and search for "webbrowser" (which is what I did to locate those URL's).

Hope this helps...

-- Lance
 
hey weez

i had the exact same problem as you did (printing contents of a webbrowser through delphi) and i have tried the solution suggested but can't get it working. Could you please tell me exactly how u got it to work. Source code would be great. Thanks a million
 
Maybe you can get it to work with SendMessage:

Try something like this:

SendMessage(WebBrowser1.Handle, WM_PRINT, 0, 0);

or

SendMessage
(WebBrowser.Handle,WM_PRINT,Screen.Width,Screen.Height);


It's just a idea, I havent tested it ... [bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
tweetie777,

The code I posted was taken directly from a working sample I put together to test it. What error message did you get? Which version of Delphi are you using?

I used Delphi 5, dropped a TWebbrowser component on a form and added two buttons. In the pushButton event of Button 1, I
added:

Code:
  WebBrowser1.navigate( '[URL unfurl="true"]http://www.borland.com/'[/URL] );

The pushButton event of Button2 was set to the code I posted previously.

I compiled it and it worked. Have you reviewed the supporting links I mentioned? I recall seeing several comments about subtleties regarding one's OS and IE versions.

Hope this helps...

-- Lance
 
thanks guys, Lance i managed to get your solution to work but is there any way to get it to print a single copy without the dialog box popping up because this is an essential requirement for my program as it sels information. Thanks a million
 
tweetie7777,

According the to FAQ that I linked to (the second one), you can't directly suppress the Print dialog unless you're using IE4. In IE5, printing is considered a security risk and therefore must be confirmed. (This is their story, not mine.)

Later in the document, yhey do refer to some additional alternatives and include some C code that shows a few different tricks. It should be possible to use the same tricks in Delphi, but I'd review the source for the TWebBrowser component to make sure of the datatypes and so forth. (If you have Professional or Enterprise versions of Delphi, you can find the source in \Source\Internet\shdocvw.pas.)

I haven't tried these out, so I don't have a specific answer, but worse comes to worse, you could determine the class name of the Print dialog and then use a timer that calls FindWindow() to get the window handle and then send a message accepting that window. That's a very crude thing, something I'd probably try as a last resort. But, it should work if nothing else does.

Hope this helps...

-- Lance
 
hey lance, thanks again for the help, i will give the findwindow() method a bash. I am a beginner so i might have to ask you for a 'step by step, what to write' solution if i can't get it going. Thanks for your help man
 
hey lance, i have had no luck in getting your findwindow() suggestion working more so because of ignorance than problems. If u could give me a piece of source code that will enable me to print a single copy, by making the print dialog automatically accept 1 copy i would be most appreciative. Thanks

lyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top