Export Crystal Reports to PDF in C#
Source: https://www.c-sharpcorner.com/UploadFile/26b237/export-crystal-report-to-pdf-in-C-Sharp/
When you want to export your Crystal Reports report to PDF format or any other format, this article provides guidance for exporting the Crystal Reports report to PDF format.
In this we can use ExportOptions for exporting the Crystal Reports report to PDF format. In the following example you can see how to export a Crystal Reports report as a PDF format file in C#. If you read my first article then it’s easy to understand this example, if not then please read my first article.
Just add the following code to export a Crystal Reports report to PDF or other format.
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 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; namespace CrystalReportDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnShow_Click(object sender, EventArgs e) { ReportDocument cryRpt = new ReportDocument(); cryRpt.Load(@"D:\C# Demos\Crystal Reports\CrystalReportDemo\CrystalReportDemo\CrystalReport1.rpt"); crystalReportViewer1.ReportSource = cryRpt; crystalReportViewer1.Refresh(); cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"D:\ASD.pdf"); MessageBox.Show("Exported Successful"); } } } |
You see that the other format options include:
- Excel
- ExcelRecord
- ExcelWorkbook
- NoFormat
- HTML32
- HTML40
- PortableDocumentFormat
- RichText
- Text
- XML
These are some of the other formats for exporting Crystal Reports in C#.
When you run the application click the Show button, it will ask for a username and password then it will show you the result in ReportViewer and then one message will be displayed, PDF Exported.
Here is your exported PDF:
Conclusion
In this article we learned how to export a Crystal Reports report in PDF or other format. I hope this example will help you to learn the basics of a C# Crystal Reports application and exporting a Crystal Reports report to another format.