Skip to main content
A newer version of this page is available. .

How to: Retain the Image URI in HTML Document

  • 3 minutes to read

The RichEditDocumentServer transforms an imported HTML document into a native document model and exports it from the native format to the resulting document’s format when it is saved.

The images contained in the document can be saved in one of the following ways when saving a document as HTML:

  • Embed images into the resulting file as base64-encoded data.

    
    <img src="data:image/png;base64,,iVBORw0KGgoAAAANSUhEUgAAAQQAAA<!-- base64 data -->" width="260" height="90" alt="" style="border-width:0px;" />
    
  • Save images as separate files. These images are saved as “image” followed by its sequential number to a folder with a name that combines the file name, an underscore and the word “files”. For example, the first png image in the resulting Test.html file is saved to the Test_files\image0.png location.

    
    <img src="test_files/image0.png" alt="" style="border-width:0px;" />
    

The table below describes the resulting document using different methods and properties:

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 a URI provider instance to obtain each image’s URI string. The built-in URI provider service (a service that implements the IUriProviderService interface) is used to register custom service providers of different types. Access the necessary provider by calling the RichEditDocumentServer.GetService method.

You can implement a custom URI provider to specify each image’s location when the document is saved to an HTML format by creating an IUriProvider descendant and registering it in the RichEditDocumentServer 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 RichEditDocumentServer.ExportOptions.HtmlOptions.EmbedImages option.

Each image in RichEditDocumentServer has an OfficeImage.Uri property that is the original image URI. The custom service’s CreateImageUri method returns the OfficeImage.Uri value used to save the original image URI to the exported HTML document.

using DevExpress.Office.Services;
using DevExpress.Office.Utils;
using System;
        public class CustomUriProvider : IUriProvider
        {
            public string CreateCssUri(string rootUri, string styleText, string relativeUri)
            {
                return String.Empty;
            }

            public string CreateImageUri(string rootUri, OfficeImage image, string relativeUri)
            {
                return image.Uri;
            }
        }
See Also