Back to Devexpress

Document Print Functionality

vcl-405571-expressricheditcontrol-print-and-import-export-document-print-functionality.md

latest9.0 KB
Original Source

Document Print Functionality

  • Mar 24, 2026
  • 4 minutes to read

TdxRichEditControl relies on the TdxComponentPrinter component from the ExpressPrinting System to print and export content to PDF. To be able to print documents in your application, you need to add a TdxComponentPrinter component and create a print link for the Rich Edit control.

You can use the following main API members to print and export document content when a print link connects a Rich Edit control and a component printer:

Print Link API Member[1]Component Printer API Member[1]Description
PreviewPreviewInvoke the Print Preview dialog for the source Chart control.
PageSetupPageSetupInvoke the Page Setup dialog.
PrintPrintInvoke the Print dialog or print chart content as is without user interaction.
PrintExPrintExLike Print, these methods print chart content but accept additional parameters, such as the number of copies.
ExportToPDFExportToPDFInvoke the PDF Export Options dialog or export chart content to a PDF document without end-user interaction.

Tip

Refer to TdxRichEditControlReportLink and TdxComponentPrinter class descriptions for detailed information on all available options.

To create a print link for a Rich Edit control at design time, add a TdxComponentPrinter component to a form. Double-click the component to open the Report Links editor dialog.

This dialog allows you to manage all print links in your application. Click the Add… button to display the Add Link dialog.

The Available Source(s) box lists all controls for which you can create a print link. Select the target Rich Edit control and click the OK button to create a print link (a TdxRichEditControlReportLink class instance) for the control in the TdxComponentPrinter component.

Close the Report Links dialog. Now you can use Print link and component printer APIs to print a document in the Rich Edit control and display the Print Preview dialog for the control.

Code Example: Export Document Content to PDF

The following code example creates a report link for an existing Rich Edit control, customizes report link settings, exports the displayed text document to a PDF file, and deletes the created report link:

delphi
uses
  dxRichEdit.Control, // Declares the TdxRichEditControl class
  dxPSCore, // Declares the TdxComponentPrinter class
  dxPSRichEditControlLnk; // Declares the TdxRichEditControlReportLink class
// ...

var
  AReportLink: TBasedxReportLink;
begin
  // Creates a Rich Edit control report link
  AReportLink := dxComponentPrinter1.AddEmptyLinkEx(TdxRichEditControlReportLink, dxRichEditControl1);
  AReportLink.Component := dxRichEditControl1; // Associates the created report link with the source control
  try
    AReportLink.PDFExportOptions.JPEGQuality := 80; // Adjusts the JPEG compression rate for export
    AReportLink.PDFExportOptions.OpenDocumentAfterExport := True; // Opens the resulting document after export
    AReportLink.ExportToPDF; // Displays "PDF Export Options" and "Save As" dialogs
  finally
    dxComponentPrinter1.DeleteLink(AReportLink.Index); // Deletes the report link after export
  end;
end;
cpp
#include "dxRichEdit.Control.hpp" // Declares the TdxRichEditControl class
#include "dxPSCore.hpp" // Declares the TdxComponentPrinter class
#include "dxPSRichEditControlLnk.hpp" // Declares the TdxRichEditControlReportLink class

// Add the following linker directives to the corresponding CPP source file
#pragma link "dxRichEdit.Control" // Required to use dxRichEdit.Control declarations
#pragma link "dxPSCore" // Required to use dxPSCore.hpp declarations
#pragma link "dxPSRichEditControlLnk" // Required to use dxPSRichEditControlLnk.hpp declarations
// ...
  TBasedxReportLink *AReportLink;
  // Creates a Rich Edit control report link
  AReportLink = dxComponentPrinter1->AddEmptyLinkEx(__classid(TdxRichEditControlReportLink), dxRichEditControl1);
  AReportLink->Component = dxRichEditControl1; // Associates the created report link with the source control
  try
  {
    AReportLink->PDFExportOptions->JPEGQuality = 80; // Adjusts the JPEG compression rate for export
    AReportLink->PDFExportOptions->OpenDocumentAfterExport = true; // Opens the exported document
    AReportLink->ExportToPDF(); // Displays "PDF Export Options" and "Save As" dialogs
  }
  __finally
  {
    dxComponentPrinter1->DeleteLink(AReportLink->Index); // Deletes the report link after export
  }

Limitations and Considerations

The TdxRichEditDocumentServer component does not support print functionality because the TdxComponentPrinter component requires a Windows handle[2] to draw document content for printing.

To see the Rich Edit print functionality in action, run the Word Processing RTF demo in the VCL Demo Center installed with compiled DevExpress demos. Click the Print or Print Preview button to open the corresponding dialog.

Download: Compiled VCL Demos

Tip

Compiled DevExpress demos ship with source code installed in the Public Documents folder (%Public%) for all users ( default ). You can find all project and source code files for the Rich Edit control demo in the following folder:

%Public%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressRichEditControl

Footnotes

  1. You can use corresponding API members of the TdxComponentPrinter and TdxRichEditControlReportLink components interchangeably if the print link for the source Rich Edit control is set as current.

  2. The TdxRichEditDocumentServer component is a non-visual component. Only a visual component can have a handle.

See Also

Document Print and Import/Export

Document Import and Export

ExpressPrinting System