Re: HTML to text



I am looking for a already done object for Delphi 2005/2006 that converts
HTML formated e-mail bodies to the raw text, it just removes the HTML
formatting codes. Anybody have any idea? It can be shareware or commerical.
If you recommend something, please give me an idea why it is great and any
known drawbacks on it. Thanks in advance!



Try

function HtmlToText(const Html: string): string;
var
WebBrowser: TWebBrowser;
Document: IHtmlDocument2;
Doc: OleVariant;
v: Variant;
Body: IHTMLBodyElement;
TextRange: IHTMLTxtRange;
begin
Result := '';

WebBrowser := TWebBrowser.Create(nil);
try
Doc := 'about:blank';
WebBrowser.Navigate2(Doc);
Document := WebBrowser.Document as IHtmlDocument2;

if (Assigned(Document)) then
begin
v := VarArrayCreate([0, 0], varVariant);
v[0] := Html;
Document.Write(PSafeArray(TVarData(v).VArray));
Document.Close;

Body := Document.body as IHTMLBodyElement;
TextRange := Body.createTextRange;
Result := TextRange.text;
end;
finally
WebBrowser.Free;
end;
end;
.



Relevant Pages

  • Re: HTML to text
    ... HTML formated e-mail bodies to the raw text, ... with full Unicode support (accented & foreign language ... You do not need to have IE nor additional character sets ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Searching local pages for visible text
    ... example that finds 61 copies of the string "center". ... in HTML, in CSS, and in the display of a page section on spelling, only. ... As you are using textContent/innerText, ... That has unveiled a bug in Google Translate: it claims to be able to ...
    (comp.lang.javascript)
  • Re: You need to identify the objects on the web page that have the values entered.
    ... Function ZipPlusFour(sAdd1 As String, _ ... Dim sResult As String ... Take the html text and put it in a file called ...
    (microsoft.public.excel.programming)
  • Re: getAttribute question
    ... oddity with IE that getAttributereturns an empty string if the ... HTML specification, ... appropriate places in the HTML 4 and DOM HTML specifications. ...
    (comp.lang.javascript)
  • Re: [PHP] generating an html intro text ...
    ... You would have to search out and pull in all closing tags. ... grab 256 characters -- The string. ... html markup should not go towards the string length count, ...
    (php.general)