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

Add an External Style Sheet for MHT Conversion

See more MHT / HTML Email Examples

Demonstrates Mht.AddExternalStyleSheet, which adds a style-sheet URL to the list of external CSS resources downloaded and embedded during conversion.

Background. This is normally unnecessary because Chilkat automatically discovers references present in the static HTML. It is useful when a stylesheet is applied by means Chilkat cannot detect from the static markup.

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.Mht;

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

procedure RunDemo;
var
  mht: TMht;
  mhtText: string;

begin
  mht := TMht.Create;

  //  Add an external style-sheet URL to the list of CSS resources downloaded and embedded during
  //  conversion.  This is normally unnecessary because Chilkat automatically discovers
  //  <link rel="stylesheet"> references in the static HTML.
  mht.AddExternalStyleSheet('https://example-code.com/crumb/style.css');

  //  Create the MHT web archive.  The external style sheet is downloaded and embedded.
  mhtText := mht.GetMHT('https://example-code.com/crumb/index.html');
  if (mht.LastMethodSuccess = False) then
    begin
      WriteLn(mht.LastErrorText);
      Exit;
    end;
  WriteLn(mhtText);


  mht.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.