VisualExportTool Class
Contains methods that work in the same manner as the export commands.
Namespace: DevExpress.XtraPrinting
Assembly: DevExpress.XtraPrinting.v24.1.dll
NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.Printing
Declaration
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.
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);
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.
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;
}
}