Here's how to use the TWebBrowser control to preview and print Microsoft Word documents.
Drop a TWebBroswer (name: WebBrowser1) on a Form and assign the next code for the NavigateComplete2 event handler:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TWordPreviewForm.FormCreate(Sender: TObject) ;
begin
//open a Word document in WebBrowser
WebBrowser1.Navigate('c:\SomeFolder\SomeDocument.doc') ;
end;
procedure TWordPreviewForm.WebBrowser1NavigateComplete2(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant) ;
begin
with (WebBrowser1.Document AS _Document) do
begin
ActiveWindow.View.ShowAll := False;
ActiveWindow.View.TableGridlines := False;
ActiveWindow.DisplayRulers := False;
ActiveWindow.View.type_ := wdPageView;
end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
The code in the above handler sets the "view type" to "Print layout", hides all non-printing characters (bookmarks, tab characters, etc.), hides table grid lines, and hides rulers.
Dont's miss: How to print a Word document contained inside a WebBrowser, and other WebBrowser tips!
Delphi tips navigator:
» Retrieving all image links from an HTML document
« Creating a roll up form (with animation)

