How To Print Multiple Copies Of A Document In Crystal Report

Introduction
 
This tutorial demonstrates how to print multiple copies of an Invoice from Crystal Report. Sometimes, it is necessary to create multiple copies of the same report. Actually, I got a requirement from client to generate multiple copies of the same invoice for seller, customer, and also for admin. So, in this example, I am going to explain how to do it using Crystal Report Viewer in C# step by step.
 
Implementation
 
Let's start implementation of our requirement given by client to create multiple copies of the same invoice.
 
Step 1

Open your Visual Studio and follow the steps given below.

File >  New > Project 

 
 
Step 2

Now, a new window will appear on your screen, as below. From left side menu, select Visual C#, choose Windows Forms Application from the list, give your application a name, and click OK.
  
 
Step 3

After this, you can see there is one blank form in your directory with the name Form1.
 
 
Step 4

Now, follow this screen and add CrystalReportViewer in this blank form from toolbox.

 
After this, your Form1 will look like this.

 
Step 5

Now, create database, add table, and enter some data on created table where product id is the primary key (No Duplication).

  
 
Step 6

Now, add CrystalReport in your project. For that, you should follow this screen. You can add this by right clicking on your project name from Solution Exploler >> Add >> Add New Item. Now, you can see a new window on your screen. From there, choose CrystalReport and click on OK.

 
 
Step 7

Add dataset on your project and add the created table in it.
 
 
To add Datatable in dataset, follow this screen and right click on dataset. Select Add >> Datatabe and add columns in it as like in your table.
 
 
Step 8

Now, we will start to write C# Code and write following code in Form1.cs but before that you should add following namespace to use crystal report in our application.
  1. using System.Data.SqlClient;  
  2. using CrystalDecisions.CrystalReports.Engine;  
Step 9

Create Database connection and write connection string and also create instance of report document within main class like this.
  1. SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Admin\Downloads\WindowsFormsApplication5\Database1.mdf;Integrated Security=True;Connect Timeout=30");  
  2.         ReportDocument rprt = new ReportDocument();  
Before writing the actual code, you need to create stored procedure for getting the data from database.
 
Step 10

Now, write the following code in load event of Form1.
  1. private void Form1_Load(object sender, EventArgs e)  
  2.         {  
  3.             //Load report from project directory  
  4.             rprt.Load(@"C:\Users\Admin\Downloads\WindowsFormsApplication5\CrystalReport1.rpt");  
  5.   
  6.             SqlCommand cmd = new SqlCommand("sp_select", con); //sp_select is stored procedure name  
  7.             cmd.CommandType = CommandType.StoredProcedure;  
  8.             SqlDataAdapter sda = new SqlDataAdapter(cmd);  
  9.             DataSet ds = new DataSet();  
  10.             sda.Fill(ds, "Newtbl_data"); // Newtbl_data is datatable name in dataset  
  11.             rprt.SetDataSource(ds);  
  12.             crystalReportViewer1.ReportSource = rprt;   
  13.         }  
Step 11

Open created CrystalReport from Solution Exploler and follow the screen.


 
 
Click on (+) sign and one new window will be popup on your screen like this. 

 
 
Now, select your dataset xml file from your project directory like this. 

 

 
 
Now, after this you can see Database Filds in Fild Exploler like this. 

 
Step 12

Now Drug and Drop Filds from fild exploler to report. in my case i have  drug and drop all the fild in report header section. for create 3 copy of same invoce we will press mouse right click in heder section and choose Insert Section Below.  

 
Same procedure follow for Section 2 (Report Header b) and create 3rd Section 3 (Report Header b). and Your Report look like this.
 
 
 
Step 13

Now, press mouse right click on Section 1 (Report Header a), Section 2 (Report Header b), Section 3 (Report Header c) and select  Section Expert.
 
 
 
Step 14

Check Checkbox New page after in paging tab. for Report Header a and Report Header b only and Click OK.
 
 
 
Step 15

Run Application and see output screen like this.
 
 
Summary
 
To create multiple reports with only singal click and get same data in multiple pages, you should only check the checkbox "New page" after paging tab in the Sesson Expert. You can also set textObject in every copy like original copy, duplicate copy, and triplicate copy of the same invoice. In my case, I have used Sheet 1, Sheet 2, and Sheet 3. 
Next Recommended Reading Crystal Report Using Stored Procedure

Codingvila
Codingvila is an educational website, developed to help tech specialists/beginners.