Link to home
Start Free TrialLog in
Avatar of jpcs
jpcs

asked on

Printing an HTML document

I have an HTML file in a IE activeX control under delphi3, and i'd like to know how to print it.
Avatar of viktornet
viktornet
Flag of United States of America image

Isn't there any procedure like Control.Print; or Control.Something.Print;???
How about the idea printing it as a bitmap....get the DC(Device Context) of the control, and then use a method to draw it onto the printer's canvas..

Regards,
Viktor Ivanov
Avatar of ZifNab
ZifNab

Hi jpcs,

 printing should be possible like :

procedure THtmlPageEditorForm.ViewerPrint1Click(Sender: TObject);
var
  VI, VO : OleVariant;
  IECommand : IOleCommandTarget;
begin
 IECommand := Document as IOleCommandTarget;
 IECommand.Exec(nil, OLECMDID_PRINT, OLECMDEXEOPT_DONTPROMPTUSER, VI, VO);
end;

{from Delphi Informant}

find also help and example sources at http://www.hyperact.com

Zif.
Avatar of jpcs

ASKER

No, it didn't work.

Let me explain it better :
   I have a fom with 2 controls:

Avatar of jpcs

ASKER

Sorry, click the submit button by mistake.

Thanks ZifNab.

As i was saying :

I have 2 controls :
   print : bitbtn control
   preview : t_webbrowser_v1 (ie ActiveX control)


When i click the print button, it should print the htm file in preview window.

The code you sent me didn't work sisnce delphi didn't recognize this line : "IECommand : IOleCommandTarget; ". It said that  IOleCommandTarget is not a valid variable kind.


What can i do? (please, tell me the full code)


Yo,
use this code. It also cleans up the references of the interfaces, the code Zif posted does not. Maybe someone should tell the people at the Delphi informant about this memory leak.

procedure TForm1.Button1Click(Sender: TObject);
var VarIn, VarOut   : OLEVariant;
    DocIDispatch    : IDispatch;
    DocOLECmdTarget : IOleCommandTarget;
begin
  VarIn := 0;
  VarOut := 0;
  DocIDispatch := WebBrowser1.Document;
  if failed(DocIDispatch.QueryInterface(IOleCommandTarget, DocOLECmdTarget))
   then Exit;
  DocIDispatch._Release;
  DocOLECmdTarget.Exec(nil, OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, VarIn, VarOut);
  DocOLECmdTarget._Release;
end;

Slash/d003303
uh, I forgot, include ActiveX in your uses clause !
Avatar of jpcs

ASKER

Thanks d003303, but it didn't work.

I get the following error on line "DocOLECmdTarget.Exec(nil, OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, VarIn, VarOut);" : ERROR : imcopatible types : 'TGUID and POINTER.

The cursor is placed between nil and OLECMDID_PRINT.


What can I do?

...seems that you didn't patched your Delphi. I use D3.02, there were several changes in the units. If you have D3 pro, open ActiveX.pas (in .\Delphi 3\source\RTL\WIN) and search for the IOleCommandTarget interface. if the declaration is NOT like this:

  IOleCommandTarget = interface(IUnknown)
    ['{b722bccb-4e68-101b-a2bc-00aa00404770}']
    function QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
      prgCmds: POleCmd; CmdText: POleCmdText): HResult; stdcall;
    function Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
      const vaIn: OleVariant; var vaOut: OleVariant): HResult; stdcall;
  end;

you will have to patch to make all your apps work properly.

Slash/d003303
Avatar of jpcs

ASKER

I're right. I havent't patched Delphi (I have Client / Server Version). Where can I get the patch? In Inprise, i only could get the release 2, but i need release 1. Is there any site in the web where it's availlable for download? If you need to contact me, My e-mail is jsantos98@usa.net

If this solves my problem, I'l give you the points.


Thanks

jpcs, you've to buy patch release 1.... sorry...
right, Patch release 1 must be purchased from Inprise. Release 2 is available for free download at their site, BUT works ONLY with an already applied Patch Release 2 !

Slash/d003303
Avatar of jpcs

ASKER

I went to inprise site, but there is a little problem : I live in Portugal, and Inprise doesn't have any place here listed in there site in order to contact it.

Any sugestion?
The contact in this case is:

INPRISE EMM
Robert-Bosch Strasse 11
63 225 Langen
Germany


Email: emm@corp.inprise.com
Phone: +49 6103 979 0
Fax: +49 6103 979 286
INPRISE Country Office

Slash/d003303
Avatar of jpcs

ASKER

Sorry for the delay Slash/d003303, but only today I could test it on Delphi 4, and... IT WORKS!!!! Thank you very much.

Please answer again to the question so I can give you the Points.

Just answer me another thing : How can I remove the text it prints in the header and footer? Example :

Header : "Page 1 of 1"
Footer : "file://f:\cdgest\data\list.html     20-9-1998"


Thanks


JPCS
ASKER CERTIFIED SOLUTION
Avatar of d003303
d003303

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 jpcs

ASKER

thanx