Back to Devexpress

How to: Save a Document as a Series of Images

wpf-11216-controls-and-libraries-rich-text-editor-examples-export-how-to-save-a-document-as-a-series-of-images.md

latest3.5 KB
Original Source

How to: Save a Document as a Series of Images

  • Jun 21, 2023
  • 2 minutes to read

This example shows how to use the DXPrinting library to save a document as a series of images. The API from the table below allows you to accomplish this task.

MemberDescription
PrintableComponentLinkBaseInitializes a new instance of the PrintableComponentLinkBase class with the default settings.
PrintableComponentLinkBase.ComponentGets or sets a IPrintable user implementation printed via the current link.
PrintableComponentLinkBase.CreateDocumentCreates a report using the current PrintingSystem.
ImageExportOptionsInitializes a new instance of the ImageExportOptions class with the default settings.
ImageExportOptions.ExportModeSpecifies whether document pages are exported to a single or multiple images.
ImageExportOptions.FormatSpecifies the image format for exporting a document.
ImageExportOptions.ResolutionSpecifies the image resolution (in DPI).
ImageExportOptions.PageRangeSpecifies the range of pages to be exported.
PrintingSystemBase.ExportToImageExports a document to the specified stream as an image. Use options to specify an image format.

The following code snippet exports the document to a series of PNG images with the specified options.

View Example

csharp
using DevExpress.XtraPrinting;
using DevExpress.XtraPrintingLinks;
using DevExpress.XtraRichEdit;

PrintableComponentLinkBase pcl = new PrintableComponentLinkBase(new PrintingSystemBase());
pcl.Component = ((IRichEditControl)richEditControl1).InnerControl;
pcl.CreateDocument(false);
ImageExportOptions imgOptions = new ImageExportOptions();
imgOptions.ExportMode = ImageExportMode.DifferentFiles;
imgOptions.Format = DXImageFormat.Png;
imgOptions.Resolution = 150;
imgOptions.PageRange = "1,3-5";
pcl.ExportToImage("export.png", imgOptions);
vb
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrintingLinks
Imports DevExpress.XtraRichEdit

Dim pcl As New PrintableComponentLinkBase(New PrintingSystemBase())
pcl.Component = (CType(richEditControl1, IRichEditControl)).InnerControl
pcl.CreateDocument(False)
Dim imgOptions As New ImageExportOptions()
imgOptions.ExportMode = ImageExportMode.DifferentFiles
imgOptions.Format = DXImageFormat.Png
imgOptions.Resolution = 150
imgOptions.PageRange = "1,3-5"
pcl.ExportToImage("export.png", imgOptions)