• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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.
0
rincewind666
Asked:
rincewind666
  • 8
  • 2
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now