Converting html files to images

I have a list of paths to html files in a listbox. I need to convert each of these html files to an image (.gif, .jpg, .bmp or whatever).  I need the delphi code or maybe a component that can do this.

I am using Delphi 6.  I am awarding 500 points (the maximum allowed) for this.
rincewind666Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HypoviaxCommented:
So you basically want the result of the HTML code as an image?

Maybe you could open them in a fullscreen webrowser, printscreen, and load this into an image:

Form properties:

formstyle: bsnone
windowstate: wsmaximized

webbrowser properties:

align: alclient

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls,clipbrd;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    WebBrowser1: TWebBrowser;
    Timer1: TTimer;
    Image1: TImage;
    Timer2: TTimer;
    procedure FormActivate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    procedure Timer2Timer(Sender: TObject);
  private
    { Private declarations }
  public
    continue:boolean;
    Index:integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormActivate(Sender: TObject);
begin
Index:=0  ;
//assume you have loaded a list of html files
webbrowser1.Navigate(listbox1.Items.Strings[Index]);
continue:=false;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (continue=true)and (index<=listbox1.Items.count-1) then
 begin
  continue:=false;
  webbrowser1.Navigate(listbox1.Items.Strings[Index]);
 end;
 if index>=listbox1.Items.Count-1 then
 timer1.enabled:=false;
end;


procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
timer2.enabled:=true;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var Bitmap:TBitmap;
begin
keybd_event(VK_SNAPSHOT,0,0,0);
try
Bitmap := TBitmap.Create;
Bitmap.LoadFromClipBoardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
except
end;
image1.picture.bitmap:=bitmap;
image1.Picture.SaveToFile(extractfilepath(application.ExeName) + inttostr(index) +  '.bmp');
continue:=true;
inc(Index);
timer2.Enabled:=false;
end;

end.

Regards,

Hypoviax



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HypoviaxCommented:
By the way, that should work as i have tested it
0
rincewind666Author Commented:
Sorry Hypoviax.  I am getting the following error:

EInvalid Graphic with message 'Unsupported Clipboard Format'

I am new with Delphi so don't know how to fix this.  Your help is greatly appreciated.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

HypoviaxCommented:
Hang on. It should work. It worked on mine. I'll retest it
0
HypoviaxCommented:
I know why you get that message. What i have done is put a try accept block around the code. This will fix an error so you won't see it when you run the exe. However in delphi you will still see this message even if it is handled. To turn it off:

Tools- Debugger Options - Language Exceptions - then down the bottom uncheck the box saying "Stop on Delphi Exceptions"

Regards,

Hypoviax
0
HypoviaxCommented:
Also make sure that timer 2 is not enabled
0
HypoviaxCommented:
>> Also make sure that timer 2 is not enabled

In the properties of the timer
0
rincewind666Author Commented:
Many thanks for your help Hypoviax.  This is excellent!  You deserve the 500 points.

If you know of a way to get rid of the taskbar in the image, please let me know.  Other than that, I am very pleased.
0
HypoviaxCommented:
Try

form1.bringtofront;

or

application.bringtofront

Put either of the above inside timer2.ontimer procedure, before the screenshot is taken...

and make the formstyle property = fsstayontop

Regards and Thanks,

Hypoviax

0
HypoviaxCommented:
The other way of course is to make your taskbar minimise of the screen when not in use. This is a windows setting under Taskbar properties (control panel)

Regards,

Hypoviax
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.