Skip to main content
All docs
V25.1
  • Document Print Functionality

    • 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 [report link] for the Rich Edit control.

    VCL Printing System: A Rich Edit Control Print Preview Example

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

    Report Link API Member[1] Component Printer API Member[1] Description
    Preview Preview Invoke the Print Preview dialog for the source Chart control.
    PageSetup PageSetup Invoke the Page Setup dialog.
    Print Print Invoke the Print dialog or print chart content as is without user interaction.
    PrintEx PrintEx Like Print, these methods print chart content but accept additional parameters, such as the number of copies.
    ExportToPDF ExportToPDF Invoke 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 report 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.

    VCL Printing System: An Empty Report Links Editor

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

    VCL Printing System: The Add Link Dialog

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

    VCL Printing System: The Report Links Editor with a Chart Control Report Link

    Close the Report Links dialog. Now you can use report 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:

    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;
    

    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 report 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