Back to Devexpress

TdxRichEditCustomDocumentServer.LoadDocument(string) Method

vcl-dxrichedit-dot-documentserver-dot-tdxricheditcustomdocumentserver-dot-loaddocument-x28-system-dot-string-x29.md

latest7.5 KB
Original Source

TdxRichEditCustomDocumentServer.LoadDocument(string) Method

Imports a document from a file (in any supported format).

Declaration

delphi
procedure LoadDocument(const AFileName: string); overload;

Parameters

NameTypeDescription
AFileNamestring

An absolute or relative path to a source document file.

|

Remarks

Call the LoadDocument procedure to import a document from a file in any supported format. Imported content replaces the current document.

A successful LoadDocument call updates Options.DocumentSaveOptions.CurrentFileName and Options.DocumentSaveOptions.CurrentFormat property values and raises the OnDocumentLoaded event.

The OnDocumentClosing event occurs immediately before a document import operation if the current document contains unsaved changes.

Source Document Format Detection

The LoadDocument procedure uses the source file name extension to identify the target format. If the file name has no extension, LoadDocument iterates through all supported formats to find the best possible match for the source document.

Import Format Support

Support for all document formats, except for plain text, is initially disabled for the TdxRichEditDocumentServer component to avoid excessive dependencies. To enable support for available formats, add all required dependencies at design time or in code:

ExtensionDocument FormatFormat ValueImport/Export SettingsSupport / Required Dependencies
TXT/txtPlain TextPlainTextOptions.Import.PlainText/Options.Export.PlainTextBuilt-in Support
RTF/rtfRich Text FormatRtfOptions.Import.Rtf/Options.Export.RtfdxRichEdit.Rtf
DOC/docMicrosoft Word® 97 – 2003DocOptions.Import.Doc/Options.Export.DocdxRichEdit.Doc
HTML/htmlHypertext Markup LanguageHtmlOptions.Import.Html/Options.Export.HtmldxRichEdit.Html
DOCX/docxOffice OpenXMLOpenXmlOptions.Import.OpenXml/Options.Export.OpenXmldxRichEdit.OpenXML

At design time, you can right-click the TdxRichEditDocumentServer component, expand the Add Unit to Support menu item, and add all required dependencies.

Code Example: Use UTF-7 to Import HTML Documents

The following code example defines the UTF-7 encoding to load an HTML document:

delphi
uses
  dxRichEdit.DocumentServer, // Declares the TdxRichEditDocumentServer component
  dxRichEdit.Html; // Declares HTML format implementation

// ...

var
  ADocumentServer: TdxRichEditDocumentServer;
begin
  ADocumentServer := TdxRichEditDocumentServer.Create(nil);
  try
    ADocumentServer.Options.Import.Html.AutoDetectEncoding := False;
    ADocumentServer.Options.Import.Html.Encoding := CP_UTF7;
    ADocumentServer.LoadDocument('Document1.html');
    // Your document processing code
  finally
    ADocumentServer.Free;
  end;
end;
cpp
#include "dxRichEdit.DocumentServer.hpp" // Declares the TdxRichEditDocumentServer component
#include "dxRichEdit.Html" // Declares HTML format implementation

// Add the following linker directives to the corresponding CPP source file:
#pragma link "dxRichEdit.DocumentServer" // Required to use dxRichEdit.DocumentServer.hpp declarations
#pragma link "dxRichEdit.Html" // Declares HTML format implementation

  TdxRichEditDocumentServer *ADocumentServer;
  try
  {
    ADocumentServer = new TdxRichEditDocumentServer(nullptr);
    ADocumentServer->Options->Import->Html->AutoDetectEncoding = false;
    ADocumentServer->Options->Import->Html->Encoding = CP_UTF7;
    ADocumentServer->LoadDocument("Document1.html");
    // Your document processing code
  }
  __finally
  {
    delete ADocumentServer;
  }

Other Document Import/Export Options

You can also use the following API members to import/export document content in different supported[1] formats:

DocBytesSpecifies document content as a byte array (in the Microsoft Word® 97 – 2003 binary format).HtmlTextSpecifies document content as a string (in the HTML format).OpenXmlBytesSpecifies document content as a byte array (in the Office OpenXML format).RtfTextSpecifies document content (as an RTF string).TextSpecifies document content (as a plain text string).LoadDocument | LoadDocumentTemplate | SaveDocumentExport/import document content to/from a file or stream in any supported format.

Footnotes

  1. Ensure that support for all required document formats is enabled; otherwise, an exception occurs.
    Refer to corresponding API member descriptions for detailed information on support for different document formats.

See Also

IdxRichEditDocument.LoadDocument Method

TdxRichEditControlBase.LoadDocument Method

Document Print and Import/Export

TdxRichEditCustomDocumentServer Class

TdxRichEditCustomDocumentServer Members

dxRichEdit.DocumentServer Unit