XtraPrinting库可以帮助开发人员导出DevExpress提供的各种控件为PDF, HTML (plus MHT), TXT (plus CSV), XLS, RTF, as well as BMP, JPEG, GIF, TIFF, PNG, EMF等多种常用的文件格式,这篇文章主要介绍最终用户如何使用打印预览窗口导出控件为PDF格式,以及使用代码导出。
1.使用打印预览窗口导出控件为多种文件格式
DevExpress提供的各种控件都可以使用XtraPrinting库进行快速地打印和打印预览
在预览窗口的右上角有一个Export Document按钮,点击该按钮就可以导出为多种文件格式
2.使用代码导出
using DevExpress.XtraPrinting;
// Create a PrintingSystem component.
DevExpress.XtraPrinting.PrintingSystem ps = new DevExpress.XtraPrinting.PrintingSystem();
// Create a link that will print a control.
DevExpress.XtraPrinting.PrintableComponentLink link = new PrintableComponentLink(ps);
// Specify the control to be printed.
link.Component = gridControl1;
// Generate a report.
link.CreateDocument();
// Export the report to a PDF file.
string filePath = @"c:\gridcontrol.pdf";
link.PrintingSystem.ExportToPdf(filePath);
// Use the code below if you want the created file to be automatically
// opened in the appropriate application.
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = filePath;
process.Start();