如何使用XtraPrinting控件导出DevExpress的控件为多种文件格式

作者:控件中国网   出处:控件中国网   2016-01-06 10:11:53   阅读:3

XtraPrinting库可以帮助开发人员导出DevExpress提供的各种控件为PDF, HTML (plus MHT), TXT (plus CSV), XLS, RTF, as well as BMP, JPEG, GIF, TIFF, PNG, EMF等多种常用的文件格式,这篇文章主要介绍最终用户如何使用打印预览窗口导出控件为PDF格式,以及使用代码导出。
 
1.使用打印预览窗口导出控件为多种文件格式
DevExpress提供的各种控件都可以使用XtraPrinting库进行快速地打印和打印预览
HelpResource.jpg
在预览窗口的右上角有一个Export Document按钮,点击该按钮就可以导出为多种文件格式
HelpResource (1).jpg
2.使用代码导出
下面采用XtraGrid控件为列,使用代码导出表格为PDF文件格式
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();
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat