1. Home
  2. Computing & Technology
  3. Delphi Programming

How to print a document/page in a TWebBrowser

By Zarko Gajic, About.com

See how to print a document/page in a TWebBrowser. Also, how to call the printer setup dialog, the page setup and the print preview screen.

Note: you must first load a page in a TWebBrowser, for example (if you have a component named WebBrowser1):
WebBrowser1.Navigate('http://delphi.about.com') ;

~~~~~~~~~~~~~~~~~~~~~~~~~
// print directly without printer dialog
procedure WBPrintNoDialog(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vIn, vOut) ;
end;

//call the printer dialog
procedure WBPrintWithDialog(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, vIn, vOut) ;
end;

// Print Preview
procedure WBPrintPreview(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DONTPROMPTUSER, vIn, vOut) ;
end;

//Call page setup dialog
procedure WBPrintPageSetup(WB: TWebBrowser) ;
var
   vIn, vOut: OleVariant;
begin
   WB.ControlInterface.ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_PROMPTUSER, vIn, vOut) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to right-align items in a TComboBox
« How to open a web site with the default web browser in a NEW window

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TWebBrowser
  6. How to print a document/page in a TWebBrowser

©2009 About.com, a part of The New York Times Company.

All rights reserved.