officefileapi-119914-word-processing-document-api-html-import-and-export-export-document-images-to-html.md
When you save a document as HTML, you can export images within the document as follows:
Embed images into an HTML file as Base64-encoded data.
Save images as separate files. Each image is named with the word “image” followed by the image’s sequential number in the document. Images are saved to a folder with the name that combines the file name, an underscore, and the word “files”. For example, the first PNG image in a Test.html file is saved to Test_files\image0.png.
Different HTML export methods produce different results, as shown in the following table:
| Export | Result |
|---|---|
| RichEditDocumentServer.HtmlText property | Images are stored in the resulting HTML file as Base64-encoded data. |
| SubDocument.GetHtmlText method | The HtmlDocumentExporterOptions.EmbedImages option specifies whether to embed images in the HTML file or save them as separate files. The method’s provider parameter allows you to specify custom URIs for images and CSS data. |
| RichEditDocumentServer.SaveDocument and RichEditDocumentServer.SaveDocumentAsync methods | The HtmlDocumentExporterOptions.EmbedImages property determines whether images are embedded in the HTML document or saved as separate files. |
Note
RichEditDocumentServer always loads images synchronously.
The HTML exporter uses a URI provider to create a URI for each image. The RichEditDocumentServer uses the following built-in URI providers:
FileBasedUriProvider - generates URIs for external images and style sheets;
DataStringUriProvider - embeds images as Base64-encoded data.
The built-in URI provider service (a service that implements the IUriProviderService interface) calls these providers when needed and allows you to register a custom provider (see the IUriProviderService.RegisterProvider method).
The following example implements and registers a custom IUriProvider to save the original image URI (OfficeImage.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;
}
}
Imports DevExpress.Office.Services
Imports DevExpress.Office.Utils
Imports System
Public Class CustomUriProvider
Implements IUriProvider
Private Function IUriProvider_CreateImageUri(rootUri As String, image As OfficeImage, relativeUri As String) As String Implements IUriProvider.CreateImageUri
Return image.Uri
End Function
Private Function IUriProvider_CreateCssUri(rootUri As String, styleText As String, relativeUri As String) As String Implements IUriProvider.CreateCssUri
Return String.Empty
End Function
End Class
private void wordProcessor_DocumentLoaded(object sender, EventArgs e)
{
IUriProviderService service = wordProcessor.GetService<IUriProviderService>();
if (service != null)
{
service.RegisterProvider(new CustomUriProvider());
}
}
Private Sub wordProcessor_DocumentLoaded(ByVal sender As Object, ByVal e As EventArgs)
Dim service As IUriProviderService = wordProcessor.GetService(Of IUriProviderService)()
If service IsNot Nothing Then
service.RegisterProvider(New CustomUriProvider())
End If
End Sub
View Example: Rich Text Editor for WinForms - Retain the Original Image URI in an HTML Document
See Also
Use Word Processing Document API to Load HTML Files or Export Documents to HTML