Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
    Traversing the Document
   [Expand]Visual Elements
    Services
    Events
    Commands
   [Expand]Member Tables
    Keyboard Shortcuts
    HTML Tag Interpretation
   [Collapse]Examples
    [Expand]Files
    [Expand]Text
    [Expand]Formatting
    [Expand]Styles
    [Expand]Lists
    [Expand]Pictures
    [Expand]Text Boxes
    [Expand]Tables
    [Expand]Layout
    [Expand]Automation
    [Expand]Search and Replace
    [Expand]Mail Merge
    [Expand]Spell Check
    [Collapse]Export-Import
      How to: Save Selected Image to a File
      How to: Determine Formatting Capabilities Required to Export the Document
      How to: Reduce the File Size When Saving a Document Containing Pictures
      How to: Retain the Image URI in HTML Document
      How To: Export Document to PDF format
      How To: Export Document to HTML format
    [Expand]Printing
    [Expand]Protection
    [Expand]User Interface Customization
    [Expand]Miscellaneous
    [Expand]Commands
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Retain the Image URI in HTML Document

This example describes HTML export in more detail and provides a solution on how to store the original image URI in the exported document.

When RichEditControl loads an HTML document, it performs HTML import and transforms the document into a native document model. When RichEditControl saves a document, it performs a document export from the native format to the resulting document's format.

When saving a document as HTML, there are two options for saving images, described in the table.

Option HTML Sample
Embed images into the resulting file as base64-encoded data
Save images as separate files. The images are named with the "image" word followed by its sequential number in a file. Images are saved to the folder with the name that is the combination of the file name, underscore and the "files" word. That is, the first png image in the resulting Test.html file is saved to the Test_files\image0.png location.

Different methods produce different results, as shown in the following table.

Export Result
RichEditControl.HtmlText property Images are contained in the resulting file as base64-encoded data.
SubDocument.GetHtmlText method The HtmlDocumentExporterOptions parameter allows specifying embedded or standalone images by setting the HtmlExportOptionsBase.EmbedImagesInHTML property.
RichEditControl.SaveDocument or RichEditControl.SaveDocumentAs methods, the SaveDocumentAsCommand command The HtmlDocumentExporterOptions.EmbedImages property accessible using the RichEditControl.ExportOptions.HtmlOptions.EmbedImages notation determines whether images are embedded or saved as separate files.

The HTML exporter uses an URI provider instance to obtain the URI string for each image. There are several built-in URI providers - the FileBasedUriProvider which provides image file names and the DataStringUriProvider that constructs a tag for embedded base64 data. The built-in URI provider service (a service that implements the IUriProviderService interface) is used to obtain a provider instance of a proper type.

You can implement a custom URI provider to specify a custom location for each image when the document is saved to an HTML format. To accomplish this, create a IUriProvider descendant and register it in RichEditControl services.

Tip

The SubDocument.GetHtmlText method allows you to specify a custom URI provider as the method's parameter, bypassing the URI provider service and the RichEditControl.ExportOptions.HtmlOptions.EmbedImages option.

Each image in RichEditControl has the OfficeImage.Uri property that is the original image URI. To save an original image URI to the exported HTML document, our custom UriProvider returns the OfficeImage.Uri value.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3189.

How would you rate this topic?​​​​​​​