Link to home
Start Free TrialLog in
Avatar of boardtc
boardtcFlag for Ireland

asked on

Print html document (C++Builder)

I know I am technically in the wrong group but there does not seem to be any C++Builder experts in the C++ Programming forum. Coming from a Delphi background to C++Builder very recently I think some Delphi experts may be able to help me.

I want to print a html document which the user does not have to see. In C++Builder 5.01 there is a component TCppWebBrowser that has a method ExecWB which makes it possible to print but I have having problems with it. I believe in Delphi the equivalent component is TWebBrowser.

Can anyone offer me any advice? If there are experts out there who can help I can provide mre information if required.

Thanks a lot,

Tom.
Avatar of inthe
inthe

Hi,
this works ok in builder4:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TVariant i,o;
WebBrowser1->Navigate(WideString("www.yahoo.com"),&i,&o);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TVariant i,o;
WebBrowser1->ExecWB(Shdocvw_tlb::OLECMDID_PRINT,Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER, &i, &o);
}


set teh visible property of the browser to false if you dont want user to see it,and use the OLECMDEXECOPT_DONTPROMPTUSER flag so the printer doesnt prompt the user.

Regards Barry
Avatar of boardtc

ASKER

Thanks a lot for the answer. The above is the code I have been having the problem with. If I run the above ot works. The problem is I want to run it all together, if I call the above OnClick events or the below in a single procedure it does not work but will work if the 2 steps are executed under seperate buttons. Put them under one or call the second OnClick from the first and it doesn't work! Am I going crazy?! Both steps work on their own without vIn or vOut too.

TVariant vIn;
TVariant vOut;
CppWebBrowser1->Navigate(WideString(sHTMLFile),&vIn,&vOut);
CppWebBrowser1->ExecWB(Shdocvw_tlb::OLECMDID_PRINT,
Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER,&vIn,&vOut);

Does it work under one button for you?

Cheers, Tom.
ASKER CERTIFIED SOLUTION
Avatar of TOndrej
TOndrej

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boardtc

ASKER

Your comment lead to my solution, thank you! TcppWebBrowser has a OnDocumentComplete event which is where I moved the ExecWB printing command.

Cheers, Tom.