如何使用XtraReport将报表导出为PDF

本文介绍如何使用XtraReport工具将报表导出为PDF格式,并提供了设置PDF导出选项及自动打开生成文件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述:这个示例将展示如何使用XtraReport将报表导出为PDF格式。


这个示例将展示如何使用XtraReport将报表导出为PDF格式。 首先需要在项目中新建一个报表(命名为XtraReport1)。还请注意,如果您希望用于打开系统中*.pdf文件的默认程序自动打开生成的文件,你可以调用StartProcess方法,示例中也有展示。

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Diagnostics;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
 
private void button1_Click( object sender, EventArgs e)
{
     // A path to export a report.
     string reportPath =  "c:\\Test.pdf" ;
 
     // Create a report instance.
     XtraReport1 report =  new XtraReport1();
 
     // Get its PDF export options.
     PdfExportOptions pdfOptions = report.ExportOptions.Pdf;
 
     // Set PDF-specific export options.
     pdfOptions.Compressed =  true ;
     pdfOptions.ImageQuality = PdfJpegImageQuality.Low;
     pdfOptions.NeverEmbeddedFonts =  "Tahoma;Courier New" ;
     pdfOptions.DocumentOptions.Application =  "Test Application" ;
     pdfOptions.DocumentOptions.Author =  "DX Documentation Team" ;
     pdfOptions.DocumentOptions.Keywords =  "XtraReports, XtraPrinting" ;
     pdfOptions.DocumentOptions.Subject =  "Test Subject" ;
     pdfOptions.DocumentOptions.Title =  "Test Title" ;
 
     // Set the pages to be exported.
     pdfOptions.PageRange =  "1, 3-5" ;
 
     // Export the report to PDF.
     report.ExportToPdf(reportPath);
 
     // Show the result.
     StartProcess(reportPath);
}
 
// Use this method if you want to automaically open
// the created PDF file in the default program.
public void StartProcess( string path)
{
     Process process =  new Process();
     try
     {
         process.StartInfo.FileName = path;
         process.Start();
         process.WaitForInputIdle();
     }
     catch { }
}
 
VB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Imports System.Diagnostics
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
' ...
 
Private Sub Button1_Click( ByVal sender  As System. Object ByVal As System.EventArgs) _
Handles Button1.Click
     ' A path to export a report.
     Dim reportPath  As String "c:\\Test.pdf"
 
     ' Create a report instance.
     Dim report  As New XtraReport1()
 
     ' Get its PDF export options.
     Dim pdfOptions  As PdfExportOptions = report.ExportOptions.Pdf
 
     ' Set PDF-specific export options.
     pdfOptions.Compressed =  True
     pdfOptions.ImageQuality = PdfJpegImageQuality.Low
     pdfOptions.NeverEmbeddedFonts =  "Tahoma;Courier New"
     pdfOptions.DocumentOptions.Application =  "Test Application"
     pdfOptions.DocumentOptions.Author =  "DX Documentation Team"
     pdfOptions.DocumentOptions.Keywords =  "XtraReports, XtraPrinting"
     pdfOptions.DocumentOptions.Subject =  "Test Subject"
     pdfOptions.DocumentOptions.Title =  "Test Title"
 
     ' Set the pages to be exported.
     pdfOptions.PageRange =  "1, 3-5"
 
     ' Export the report to PDF.
     report.ExportToPdf(reportPath)
 
     ' Show the result.
     StartProcess(reportPath)
End Sub
 
' Use this method if you want to automaically open
' the created PDF file in the default program.
Public Sub StartProcess( ByVal path  As String )
     Dim process  As New Process()
     Try
         process.StartInfo.FileName = path
         process.Start()
         process.WaitForInputIdle()
     Catch
     End Try
End Sub
文章转自:https://www.evget.com/article/2012/11/26/18159.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值