Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Convert HTML to plain-text

See more HTML-to-XML/Text Examples

Demonstrates how to convert HTML to plain-text.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.HtmlToText;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  h2t: THtmlToText;
  html: string;
  plainText: string;

begin
  //  This example assumes the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  h2t := THtmlToText.Create;

  //  Set the HTML:

  html := '<html><body><p>This is a test.</p><blockquote>Here is text within a blockquote</blockquote></body></html>';

  plainText := h2t.ToText(html);

  WriteLn(plainText);

  //  The output looks like this:

  //  This is a test.
  //  
  //      Here is text within a blockquote


  h2t.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.