Printing from TAdvWebBrowser

Hi, Is there any way to print Web pages from TAdvWebBrowser?

We can use ExecWB method and print without print dialog in TWebBrowser.
It would be very helpful if I could print from TAdvWebBrowser as well.

Hi,

you can use AdvWebBrowser1.ExecuteJavaScript('window.print();'); to print.
Note that there is no dialog less printing, unless you use the CaptureScreenShot method and then print the bitmap directly at client level.

Thank you for your reply.
Then I'm trying to print a whole web page in one bitmap without scrollbars of webbrowser.
As your suggestion,I need to get "document.body.scrollHeight" to use CaptureScreenShot method.

I tried this code but returned null.

procedure TForm1.Button5Click(Sender: TObject);
begin
AdvWebBrowser1.ExecuteJavascript('function getH{return document.body.scrollHeight;};getH();',
procedure (const AValue:string)
begin
ShowMessage(AValue);//=null
end
);

Is there any good solution?

I found mistake of javascript.
I changed below.

procedure TForm1.Button5Click(Sender: TObject);
begin
AdvWebBrowser1.ExecuteJavascript('function getH(){return document.documentElement.scrollHeight;};getH();',
procedure (const AValue:string)
begin
ShowMessage(AValue);//=OK
end
);

Hi Yebisu,
I have same problem.
Can you help me how did you solve this problem. How can i take CaptureScreenShot of my page and print it without printer dialog window.
Thank You

Here is a complete sample.

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AdvCustomControl,
  AdvWebBrowser, VCL.Printers, AdvTypes;

type
  TForm1 = class(TForm)
    AdvWebBrowser1: TAdvWebBrowser;
    Button1: TButton;
    PrinterSetupDialog1: TPrinterSetupDialog;
    procedure Button1Click(Sender: TObject);
    procedure AdvWebBrowser1CaptureScreenShot(Sender: TObject;
      AScreenShot: TAdvBitmap);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AdvWebBrowser1CaptureScreenShot(Sender: TObject;
  AScreenShot: TAdvBitmap);
begin
  Printer.BeginDoc;
  Printer.Canvas.Draw(0, 0, AScreenShot.Graphic);
  Printer.EndDoc;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  AdvWebBrowser1.CaptureScreenShot;
end;

end.