Taking Screenshots on web pages from Delphi

ST3VO
ST3VO used Ask the Experts™
on
Hi all,

Up to now I've only been able to use TBrowser as IE and import Mozilla ActiveX.
I've thought of another posible was to do this.

From within Delphi, is it possible to send a command to any browser to (either open and go to a url..then take a sshot and close or better do this without opening the browser (hidden) and take a screenshot.
I'm opened to different way's but it has to be done from delphi or at least controlled from delphi.

Hope this can be done somehow. I know there are some websites that do this so if it can be done using a web language I'm pretty sure Delphi can do it as it must be more powerful than any web language (I guess).

Anyway, hope you can help.

thx

St3vo
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sorry for asking, but what's wrong with using TWebBrowser to take it? Most websites that creates thumbnails of other websites are using just that (InternetExplorer.Application COM), or something similar.

Before you're able to take a screenshot of a website, you'll need to render it somehow. So, basically, you can 1) use an already existing object to render the website (like TWebBrowser) or 2) create your own object for rendering a website (and that wont be easy).

Author

Commented:
TWebBrowser works wiell and I have Mozilla too but I need to do the same for Safari, Chrome and Opera :o(
Alright, fair enough. But can you give me a little insight to why you want to do it like that? What are you trying to make exactly? We might be able to help you better knowing that. ;)
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Author

Commented:
I do lots of websites and I'm always having to check for browser issues. Instead of having to open every browser and check or manually take a screenshot I want to make a tool that will do this on all major browsers. I can now do it for IE and Firefox but I cannot find an activex to import for opera, chrome and safari so I though that it MIGHT be easier to call the browsers from delphi if it cannot be added to delphi.

hope this helps

st3vo
Ah :) I'll look into it later and get back to you.
There are tons of free software applications and browser extensions that allow you to capture screenshots of web pages in one click. For instance, Firefox users can grab the excellent Firefox add-on while Windows users can try something like SnagIt or even the Snipping tool that comes preloaded with Windows Vista.

The only issue with these applications is that they require installation and they may not work with every web browser. For instance, SnagIt can have trouble capturing long web pages in Opera while Fireshot will only work with web pages that are viewed in Firefox so you would need a separate screen capture solution for pages that are opened inside Internet Explorer or Google Chrome.

Well, not anymore.

http://www.labnol.org/internet/full-screenshots-of-web-pages/9222/

Aviary, which is a suite of free online image editing tools, has released a new web based screen capture service that lets you shoot pages without installing or downloading anything.

Just open the web page that you want to capture, go to the address bar of the browser and type "aviary.com/" just before the http:// part of the URL.

For instance, if you are trying to capture the Google homepage at http://google.com, the new URL will become aviary.com/http://google.com  hit Enter and there you have an editable screenshot image of Google in the browser. You can save the image to the desktop or add annotations using the Type Tool.

Author

Commented:
Hi thiagoblimeira,

Thanks for the comment but it's not what or why I want this.

I have every major browser already installed in my computer and I could open them all one by one and take a sceenshot on how the website look on the different browsers.
I know there are services that already do it but I don't want to use anyone else's service.
It's a design tool. When I write some code and look at it on browser 1 for example and the page looks great ... I then open the page on browser 2 and it looks broken so I want to do that same thing but via delphi.

Hope this helps

thanks

st3vo
Eddie ShipmanAll-around developer

Commented:
The problem with this is that each of the browsers uses different mechanisms for taking screenshots.

If they all followed the same standards, then it would be easy but they don't.

It is going to take a lot of work to do what you are asking and you need to gather your information from each of the browser manufacturers support means; i.e. newsgroups, forums, mailing lists etc.

One other, much easier way to do this is to use an automation tool such as AutoIt! to activate the browser you want and send it key strokes to capture the screen. It has a DLL and Delphi wrapper so coding is very easy.

DLL and Wrapper included with AutoIt2 downloadable here: (this is the one I use)
http://www.autoitscript.com/cgi-bin/countdown.pl?AutoIt/AutoItDLL.zip 

AutoIt3 is downloadable here:    http://www.autoitscript.com/autoit3/downloads.shtml
DLL Wrapper for AutoIt3 is here: http://www.autoitscript.com/forum/index.php?showtopic=54219
Eddie ShipmanAll-around developer

Commented:
BTW, if you need help with the AutoIt script, let me know.

Author

Commented:
Hi Eddie,


I've downloaded it and created a package and imported the pas file and compiled it etc...

Are there any demo's somewhere as I cannot figure out where to start with it :o/

thx

Eddie ShipmanAll-around developer

Commented:
Here is a sample of logging in to Hotmail using it. I use DCTray and have a popup menu.

unit uEmailLauncher;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  Forms,Dialogs, StdCtrls, ShellAPI, AUTOITDLL, Menus, DCTray;
 
type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Close1: TMenuItem;
    N1: TMenuItem;
    MyHotmailAcct: TMenuItem;
    DCTrayIcon1: TDCTrayIcon;
    procedure Close1Click(Sender: TObject);
    procedure MyHotmailAcctClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
const
  HOTMAIL = 'Sign In';
 
procedure HotmailLogin(Auser, APassword: String);
begin
  if AUTOIT_IfWinExist(HOTMAIL, '') = 0 then
  begin
    ShellExecute(0, 'open', PChar('http://www.hotmail.com'), '', '', SW_SHOW);
    AutoIt_WinWaitActive(HOTMAIL, '', 60);
  end
  else
  begin
    AUTOIT_WinActivate(HOTMAIL, '');
  end;
 
  AUTOIT_Sleep(3000);
 
  if AUTOIT_IfWinActive(HOTMAIL, '') = 1 then
  begin
    AutoIt_Send(PChar(Auser));
    AutoIt_Send('{TAB}');
 
    AutoIt_Send(PChar(APassword));
    AutoIt_Send('{ENTER}');
  end;
end;
 
procedure TForm1.MyHotmailAcctClick(Sender: TObject);
begin
  HotmailLogin('myhotmailacct@hotmail.com', 'mypswd');
end;
 
procedure TForm1.Close1Click(Sender: TObject);
begin
  Close;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  AUTOIT_SetTitleMatchMode(2);
end;
 
end.

Open in new window

Author

Commented:
Great!

On my way home now so will test it as soon as I get there and get back to you.

thanks

Author

Commented:
Hi Eddie,

Thanks, that works great.

Could you please get me started on what I need to do with the browser issue using this system?

I just need help to get started then I will take it from there.

Any chance?

thx

st3vo
Eddie ShipmanAll-around developer

Commented:
Ok, I'll take a snapshot of FF using AutoIt and post the code later this evening.

Author

Commented:
Fantastic, thanks a million :o)
All-around developer
Commented:
Ok, here you go, for Opera and others, it would be basically the same thing.
unit uBrowserScreenShots;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ShellAPI, AutoItDLL, ClipBrd, ExtCtrls, StdCtrls;
 
type
  TForm1 = class(TForm)
    btnFF: TButton;
    btnIE: TButton;
    edtURL: TEdit;
    Label1: TLabel;
    ScrollBox1: TScrollBox;
    Image1: TImage;
    procedure btnFFClick(Sender: TObject);
    procedure btnIEClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure TakeScreenShot;
  end;
 
var
  Form1: TForm1;
 
 
implementation
 
{$R *.dfm}
 
procedure TForm1.TakeScreenShot;
begin
  // Sends Alt+PrintScreen to the Active Window...
  AutoIt_Send('!{PRINTSCREEN}');
  // Copies the clipboard to the TImage on the form
  if Clipboard.HasFormat( CF_PICTURE ) then
    Image1.Picture.Assign( ClipBoard );
  // Now bring this window to front...
  SetForegroundWindow(Form1.Handle);
end;
 
procedure TForm1.btnFFClick(Sender: TObject);
begin
  // Need to modify to get the path to firefox.exe.
  ShellExecute(0, 'open', PChar('C:\Program Files\Mozilla Firefox\firefox.exe'), PChar(edtURL.Text), '', SW_SHOWMAXIMIZED);
  // We are going to wait 7 seconds for it to load
  AUTOIT_Sleep(7000);
  TakeScreenShot;
end;
 
procedure TForm1.btnIEClick(Sender: TObject);
begin
  // Need to modify to get the path to iexplore.exe
  ShellExecute(0, 'open', PChar('C:\Program Files\Internet Explorer\iexplore.exe'), PChar(edtURL.Text), '', SW_SHOWMAXIMIZED);
  // We are going to wait 7 seconds for it to load
  AUTOIT_Sleep(7000);
  TakeScreenShot;
end;
 
end.

Open in new window

Author

Commented:
Works great Eddie :o)

You're a star!!!

Thanks a million for your help

cheers

St3vo

Author

Commented:
Perfect :o)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial