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,

Who is Participating?
TOndrejConnect With a Mentor Commented:
Navigate sends request and returns; OnNavigateComplete event is called after the page has been loaded.

So you need to do something like this (pseudo-code):

clear flag;
loop while flag not set; (in OnNavigateComplete set flag)
this works ok in builder4:

void __fastcall TForm1::Button1Click(TObject *Sender)
TVariant 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
boardtcAuthor Commented:
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;

Does it work under one button for you?

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

Cheers, Tom.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.