When working with Delphi, the TWebBrowser component allows you to create a customized Web browsing application or to add Internet, file and network browsing, document viewing, and data downloading capabilities to your applications.
Web page … Save As; How to save a web page from TWebBrowser
When using Internet Explorer, you are allowed you to view the source HTML code of a page and to save that page as a file on your local drive. If you are viewing a page that you wish to keep, go to the File/Save As … menu item. In the dialog box that opens, you have several file types offered. Saving the page as a different filetype will affect how the page is saved…
The TWebBrowser component (located on the “Internet” page of the Component Palette) provides access to the Web browser functionality from your Delphi applications. In general, you’ll want to enable saving of a web page displayed inside a WebBrowser as a HTML file to a disk.
Saving a web page as a raw HTML
If you only want to save a web page as a raw HTML you would select “Web Page, HTML only (*.htm, *.html)”. It will simply save the current page’s source HTML to your drive intact. This action will NOT save the graphics from the page or any other files used within the page, which means that if you loaded the file back from the local disk, you would see broken image links.
Here’s how to save a web page as raw HTML using Delphi code:
...
procedure WB_SaveAs_HTML(WB : TWebBrowser; const FileName : string) ;
var
PersistStream: IPersistStreamInit;
Stream: IStream;
FileStream: TFileStream;
begin
if not Assigned(WB.Document) then
begin
ShowMessage('Document not loaded!') ;
Exit;
end;
PersistStream := WB.Document as IPersistStreamInit;
FileStream := TFileStream.Create(FileName, fmCreate) ;
try
Stream := TStreamAdapter.Create(FileStream, soReference) as IStream;
if Failed(PersistStream.Save(Stream, True)) then ShowMessage('SaveAs HTML fail!') ;
finally
FileStream.Free;
end;
end; (* WB_SaveAs_HTML *)
Usage sample:
WebBrowser1.Navigate('http://delphi.about.com') ;
//then save
WB_SaveAs_HTML(WebBrowser1,'c:\WebBrowser1.html') ;




It always give me the mesagge “Document Not Loaded!” and does´nt save anything…any idea…?