[Delphi] Capturing a Screen Shot of Web page using TWebBrowser

[Delphi] Capturing a Screen Shot of Web page using TWebBrowser

TWebBrowser is not only for Webpage visiting, full page captures and save as Jpg is available.

The program shows below is TWebbrowser to visit a website and capture the screen to save to JPG:

uses ActiveX;

procedure WebBrowserScreenShot(const wb: TWebBrowser; const fileName: TFileName) ;
var
  viewObject : IViewObject;
  r : TRect;
  bitmap : TBitmap;
begin
  if wb.Document <> nil then
  begin
    wb.Document.QueryInterface(IViewObject, viewObject) ;
    if Assigned(viewObject) then
    try
      bitmap := TBitmap.Create;
      try
        r := Rect(0, 0, wb.Width, wb.Height) ;

<span id="p8e7fef51">This Sildenafil citrate medicine is all you need to consume No Fall capsule and Maha Rasayan capsule daily two times with water in the  <a href="http://www.glacialridgebyway.com/windows/Sabin%20House%20in%20Murdock.html">viagra tablets for sale</a> morning after breakfast and in the evening after supper consistently for 3 to 4 months. Don't ever feel as if long periods crazy allows you <a href="http://www.glacialridgebyway.com/windows/Green%20Lake%20Bible%20Lake%20Camp%20Chapel.html">purchase viagra online</a>  to look higher. Liquorice Liquorice is  <a href="http://www.glacialridgebyway.com/mid-6810">purchase levitra online</a> used in herbal teas, candy, and also some beverages. The oil <a href="http://www.glacialridgebyway.com/windows/Glacial%20Ridge%20Bike%20Trail.html">glacialridgebyway.com</a> viagra 25mg prix should be rubbed over a prostatic gland smoothly. </span>        bitmap.Height := wb.Height;
        bitmap.Width := wb.Width;

        viewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Application.Handle, bitmap.Canvas.Handle, @r, nil, nil, 0) ;

        with TJPEGImage.Create do
        try
          Assign(bitmap) ;
          SaveToFile(fileName) ;
        finally
          Free;
        end;
      finally
        bitmap.Free;
      end;
    finally
      viewObject._Release;
    end;
  end;
end;

RefLink : http://delphi.about.com/od/vclusing/a/wb_scren_shot.htm

Leave a Reply