Skip to main content
Table of Contents

Import and export

HTML with TTMSFNCRichEditorHTMLIO

TTMSFNCRichEditorHTMLIO (a descendant of TTMSFNCRichEditorIO) handles HTML import and export. Drop it on the form or create it in code:

HTML with TTMSFNCRichEditorIOPascalC++
var
  IO: TTMSFNCRichEditorHTMLIO;
  ss: TStringStream;
  html: string;
begin
  IO := TTMSFNCRichEditorHTMLIO.Create(nil);
  try
    IO.RichEditor := RichEditor1;

    // Import HTML from file
    IO.Load('document.html');

    // Import HTML from string
    IO.LoadHTML('<b>Hello</b> <i>World</i>');

    // Export to HTML file
    IO.Save('output.html');

    // Export to HTML string (via a stream)
    ss := TStringStream.Create;
    try
      IO.Save(ss);
      html := ss.DataString;
    finally
      ss.Free;
    end;
  finally
    IO.Free;
  end;
end;
TTMSFNCRichEditorHTMLIO *IO = new TTMSFNCRichEditorHTMLIO(NULL);
try
{
  IO->RichEditor = RichEditor1;

  // Import HTML from file
  IO->Load("document.html");

  // Import HTML from string
  IO->LoadHTML("<b>Hello</b> <i>World</i>");

  // Export to HTML file
  IO->Save("output.html");

  // Export to HTML string (via a stream)
  TStringStream *ss = new TStringStream();
  try
  {
    IO->Save(ss);
    System::UnicodeString html = ss->DataString;
  }
  __finally
  {
    delete ss;
  }
}
__finally
{
  delete IO;
}

PDF output with TTMSFNCRichEditorPDFIO

TTMSFNCRichEditorPDFIO converts editor content to PDF:

PDF output with TTMSFNCRichEditorPDFIOPascalC++
var PDF: TTMSFNCRichEditorPDFIO;
begin
  PDF := TTMSFNCRichEditorPDFIO.Create(nil);
  try
    PDF.RichEditor := RichEditor1;
    PDF.Save('output.pdf');
  finally
    PDF.Free;
  end;
end;
TTMSFNCRichEditorPDFIO *PDF = new TTMSFNCRichEditorPDFIO(NULL);
try
{
  PDF->RichEditor = RichEditor1;
  PDF->Save("output.pdf");
}
__finally
{
  delete PDF;
}

TTMSFNCRichEditorPrintIO sends editor content to the system print dialog:

Print output with TTMSFNCRichEditorPrintIOPascalC++
var Print: TTMSFNCRichEditorPrintIO;
begin
  Print := TTMSFNCRichEditorPrintIO.Create(nil);
  try
    Print.RichEditor := RichEditor1;
    Print.Print;
  finally
    Print.Free;
  end;
end;
TTMSFNCRichEditorPrintIO *Print = new TTMSFNCRichEditorPrintIO(NULL);
try
{
  Print->RichEditor = RichEditor1;
  Print->Print();
}
__finally
{
  delete Print;
}

Combining HTML and PDF export with progress handling

Combining HTML and PDF export with progress handlingPascalC++
procedure TForm1.SaveDocument;
var
  IO: TTMSFNCRichEditorHTMLIO;
  PDF: TTMSFNCRichEditorPDFIO;
begin
  IO := TTMSFNCRichEditorHTMLIO.Create(nil);
  PDF := TTMSFNCRichEditorPDFIO.Create(nil);
  try
    IO.RichEditor := RichEditor1;
    PDF.RichEditor := RichEditor1;

    IO.Save('report.html');
    PDF.Save('report.pdf');
  finally
    IO.Free;
    PDF.Free;
  end;
end;
void __fastcall TForm1::SaveDocument()
{
  TTMSFNCRichEditorHTMLIO *IO = new TTMSFNCRichEditorHTMLIO(NULL);
  TTMSFNCRichEditorPDFIO *PDF = new TTMSFNCRichEditorPDFIO(NULL);
  try
  {
    IO->RichEditor = RichEditor1;
    PDF->RichEditor = RichEditor1;

    IO->Save("report.html");
    PDF->Save("report.pdf");
  }
  __finally
  {
    delete IO;
    delete PDF;
  }
}

See also