Back to Devexpress

VisualExportTool Class

windowsforms-devexpress-dot-xtraprinting-a916b64f.md

latest5.6 KB
Original Source

VisualExportTool Class

Contains methods that work in the same manner as the export commands.

Namespace : DevExpress.XtraPrinting

Assembly : DevExpress.XtraPrinting.v25.2.dll

NuGet Package : DevExpress.Win.Printing

Declaration

csharp
[DXLicenseWinReporting]
public class VisualExportTool
vb
<DXLicenseWinReporting>
Public Class VisualExportTool

Remarks

The VisualExportTool class allows you to invoke the Export Options dialog so that the user can specify export options, and export a document to the specified format using the specified options.

Example - Specify Export Options and Export to PDF

The following code invokes the PDF Export Options dialog with the Author field already filled in, prompts the user for the file location, exports the report to PDF, saves the PDF file, and asks the user whether to open the file with the default application.

csharp
var report = new XtraReport1();
report.CreateDocument();
var pdfExportOptions = new PdfExportOptions();
// Specify export options before a dialog is displayed. 
pdfExportOptions.DocumentOptions.Author = "VisualExportTool";
VisualExportTool.ExportFile(pdfExportOptions, report.PrintingSystem);
vb
Dim report = New XtraReport1()
report.CreateDocument()
Dim pdfExportOptions = New PdfExportOptions()
' Specify export options before a dialog is displayed. 
pdfExportOptions.DocumentOptions.Author = "VisualExportTool"
VisualExportTool.ExportFile(pdfExportOptions, printControl.PrintingSystem)

Example - Modify the Built-In Export to PDF Command

Use the VisualExportTool class to implement export commands that work in the same manner as built-in export commands and performs additional actions before or after the export.

The following code modifies the Export to PDF command, specifies the Author document option before the PDF Export Options dialog is invoked, and allows you to create a log entry after the export.

View Example

csharp
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using System;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text;
// ...
private void simpleButton2_Click(object sender, EventArgs e) {
    var report = new XtraReport1();
    var preview = new ReportPrintTool(report);
    preview.PrintingSystem.AddCommandHandler(new CustomPDFExportCommandHandler());
    preview.ShowRibbonPreviewDialog();
}
// ...
public class CustomPDFExportCommandHandler : DevExpress.XtraPrinting.ICommandHandler {
    public virtual void HandleCommand(PrintingSystemCommand command,
    object[] args, IPrintControl printControl, ref bool handled) {
        if (!CanHandleCommand(command, printControl))
            return;

        var pdfExportOptions = new PdfExportOptions();
        // You can configure your export options.
        pdfExportOptions.DocumentOptions.Author = "VisualExportTool";
        VisualExportTool.ExportFile(pdfExportOptions, printControl.PrintingSystem);
        // You can add a log entry about the PDF export operation.

        handled = true;
    }

    public virtual bool CanHandleCommand(PrintingSystemCommand command, IPrintControl printControl) {
        return command == PrintingSystemCommand.ExportPdf;
    }
}
vb
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
Imports System
Imports System.Drawing.Imaging
Imports System.Globalization
Imports System.Text
' ...
Private Sub simpleButton2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton2.Click
    Dim report = New XtraReport1()
    Dim preview = New ReportPrintTool(report)
    preview.PrintingSystem.AddCommandHandler(New CustomPDFExportCommandHandler())
    preview.ShowRibbonPreviewDialog()
End Sub
' ...
Public Class CustomPDFExportCommandHandler
    Implements DevExpress.XtraPrinting.ICommandHandler

    Public Overridable Sub HandleCommand(ByVal command As PrintingSystemCommand, ByVal args() As Object, ByVal printControl As IPrintControl, ByRef handled As Boolean) Implements DevExpress.XtraPrinting.ICommandHandler.HandleCommand
        If Not CanHandleCommand(command, printControl) Then
            Return
        End If

        Dim pdfExportOptions = New PdfExportOptions()
        ' You can configure your export options.
        pdfExportOptions.DocumentOptions.Author = "VisualExportTool"
        VisualExportTool.ExportFile(pdfExportOptions, printControl.PrintingSystem)
        ' You can add a log entry about the PDF export operation.

        handled = True
    End Sub

    Public Overridable Function CanHandleCommand(ByVal command As PrintingSystemCommand, ByVal printControl As IPrintControl) As Boolean Implements DevExpress.XtraPrinting.ICommandHandler.CanHandleCommand
        Return command = PrintingSystemCommand.ExportPdf
    End Function
End Class

Inheritance

Object VisualExportTool

See Also

VisualExportTool Members

DevExpress.XtraPrinting Namespace