Delphi .NET (2) Database (71) Delphi IDE (90) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
Print a HTML web page from my application
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:
I need to print a web page or a local HTML file from my application, but the TWebBrowser class has no print method. How can I print my document then?
Answer:
Looking into MSHTML.pas, you'll notice that IHTMLWindow3 has a print method. The question is how to a IHTMLWindow3 interface von TWebBrowser.
The solution is to use a regular TWebBrowser component, use Navigate() to load the desired document and put the code for printing in the OnNavigateComplete event.  | |  | | procedure TForm1.WebBrowser_V1NavigateComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
HTMLDoc: IHTMLDocument2;
HTMLWnd: IHTMLWindow2;
HTMLWindow3: IHTMLWindow3;
begin
HTMLDoc := (Sender as TWebBrowser).Document as IHTMLDocument2;
if HTMLDoc = nil then
raise Exception.Create('Could not convert the WebBrowser to an IHTMLDocument2');
HTMLWnd := HTMLDoc.parentWindow;
HTMLWindow3 := HTMLWnd as IHTMLWindow3;
HTMLWindow3.print;
end;
begin
WebBrowser1.Navigate('http://www.yahoo.com/');
end; | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|