officefileapi-devexpress-dot-xtrarichedit-dot-richeditdocumentserverextensions-dot-exporttoimage-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-devexpress-dot-xtrarichedit-dot-export-dot-image-dot-richeditimageexportoptions-x29.md
Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.
Exports a document to a list of images. Allows you to specify export options.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.Docs.v25.2.dll
NuGet Package : DevExpress.Document.Processor
public static IReadOnlyList<Stream> ExportToImage(
this Document document,
RichEditImageExportOptions options
)
<ExtensionAttribute>
Public Shared Function ExportToImage(
document As Document,
options As RichEditImageExportOptions
) As IReadOnlyList(Of Stream)
| Name | Type | Description |
|---|---|---|
| document | Document |
A document to export.
| | options | RichEditImageExportOptions |
An object that contains image export options.
|
| Type | Description |
|---|---|
| IReadOnlyList<Stream> |
A list of stream objects. Each object contains a separate document page converted to an image.
|
The following code sample exports first three document pages to images in JPEG format:
using DevExpress.XtraRichEdit.Export.Image;
using DevExpress.XtraRichEdit;
using DevExpress.Drawing;
using RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
wordProcessor.LoadDocument(@"C:\Documents\Alice.docx");
var options = new RichEditImageExportOptions();
options.Format = DXImageFormat.Jpeg;
options.PageRange = "1-3";
var streamList = wordProcessor.Document.ExportToImage(options);
int i = 1;
foreach (var stream in streamList) {
var newFileName = Path.GetFileNameWithoutExtension("ExportedPage.jpeg") + i + Path.GetExtension("ExportedPage.jpeg");
StreamToFile(stream, newFileName);
i++;
stream.Dispose();
}
static void StreamToFile(Stream stream, string filePath)
{
using (var fileStream = File.Create(filePath))
{
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
}
}
Imports DevExpress.XtraRichEdit.Export.Image
Imports DevExpress.XtraRichEdit
Imports DevExpress.Drawing
Imports RichEditDocumentServer wordProcessor = New RichEditDocumentServer()
wordProcessor.LoadDocument("C:\Documents\Alice.docx")
Dim options = New RichEditImageExportOptions()
options.Format = DXImageFormat.Jpeg
options.PageRange = "1-3"
Dim streamList = wordProcessor.Document.ExportToImage(options)
Dim i As Integer = 1
For Each stream In streamList
Dim newFileName = Path.GetFileNameWithoutExtension("ExportedPage.jpeg") & i & Path.GetExtension("ExportedPage.jpeg")
StreamToFile(stream, newFileName)
i += 1
stream.Dispose()
Next stream
Shared Sub StreamToFile(ByVal stream As Stream, ByVal filePath As String)
Using fileStream = File.Create(filePath)
stream.Seek(0, SeekOrigin.Begin)
stream.CopyTo(fileStream)
End Using
End Sub
See Also
RichEditDocumentServerExtensions Class