1. About.com
  2. Computing & Technology
  3. Delphi

Discuss in my forum

How to print a document/page in a TWebBrowser

By , About.com Guide

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

©2012 About.com. All rights reserved. 

A part of The New York Times Company.