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.
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");
}
}
}
In the code above we uesd the ReportDocument.ExportToDisk() function and in that the first parameter is the Export format type and the second parameter is the path to store the PDF file. Other options for exporting Crystal Reports to other formats are as follows:
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.
No comments:
Post a Comment