Skip to main content
Table of Contents

Import and export

HTML with TTMSFNCRichEditorIO

TTMSFNCRichEditorIO handles HTML import and export. Drop it on the form or create it in code:

HTML with TTMSFNCRichEditorIOPascalC++
var IO: TTMSFNCRichEditorIO;
begin
  IO := TTMSFNCRichEditorIO.Create(nil);
  try
    IO.RichEditor := RichEditor1;

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

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

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

    // Export to HTML string
    var html := IO.SaveToString;
  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.SaveToFile('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: TTMSFNCRichEditorIO;
  PDF: TTMSFNCRichEditorPDFIO;
begin
  IO := TTMSFNCRichEditorIO.Create(nil);
  PDF := TTMSFNCRichEditorPDFIO.Create(nil);
  try
    IO.RichEditor := RichEditor1;
    PDF.RichEditor := RichEditor1;

    IO.SaveToFile('report.html');
    PDF.SaveToFile('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