Blue Theme Orange Theme Green Theme Red Theme
 
MindFusion's Components
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Crystal Reports » Tip: How to Print a Crystal Report Programmatically in ASP.NET?

Tip: How to Print a Crystal Report Programmatically in ASP.NET?

You can print a Crystal Report using print option of Crystal Report Viewer. However, there are occasions when you want your application to print a report direct to printer without viewing the report in Crystal Report Viewer.

Author Rank:
Technologies: .NET 1.0/1.1,Visual C# .NET
Total downloads :
Total page views :  73132
Rating :
 5/5
This article has been rated :  1 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
Become a Sponsor



You can print a Crystal Report using print option of Crystal Report Viewer. However, there are occasions when you want your application to print a report direct to printer without viewing the report in Crystal Report Viewer.

 

The ReportDocument class provides PrintToPrinter method that may be used to print a CR direct to the printer. If no printer is selected, the default printer will be used to send the printing pages to.

 

The PrintToPrinter method takes four parameters.

 

nCopies : Indicates the number of copies to print.

collated : Indicates whether to collate the pages.

startPageN : Indicates the first page to print.

endPageN : Indicates the last page to print.

 

The following steps will guide you to achieve the same:

 

  1. Add crystal report (.cr) file to your ASP.NET application.
  2. Add a report instance on the page level.

    Dim report As MyReport = New MyReport

 

  1. Populate reports data on Page_Init 

     
    ' Get data in a DataSet or DataTable

        Dim ds As DataSet = GetData()

        ' Fill report with the data

     report.SetDataSource(ds)

 

  1. Print Report
    report.PrintToPrinter(1, False, 0, 0)

 

If you wish to print certain page range, change last two parameters From to To page number.

 

If you want to set page margins, you need to create a PageMargin object and set PrintOptions of the ReportDocument.

 

The following code sets page margins and printer name:

 

Dim margins As PageMargins =  Report.PrintOptions.PageMargins

   margins.bottomMargin = 200

   margins.leftMargin = 200

   margins.rightMargin = 50

   margins.topMargin = 100

   Report.PrintOptions.ApplyPageMargins(margins)

 

   ' Select the printer name

   Report.PrintOptions.PrinterName = printerName

 


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Mahesh Chand
Mahesh is a software developer with over 13 years of experience building systems for Financial and Banking, Engineering & Architectural, Imaging, Construction, Biological & Pharmaceuticals, Healthcare and Education industries. His expertise is Windows Forms, ASP.NET, Silverlight, WPF, WCF, Visual Studio 2010, SQL Server, and Oracle. If you are looking for a Windows Forms, ASP.NET, WPF, Silverlight, C#, VB.NET, Oracle, and SQL Server Consultant in Philadelphia area or remote location, drop me a line at MAHESH [AT] C-SHARPCORNER [DOT] COM.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments
go to another page by kavita On October 26, 2006

 hi

I m kavita,My problem is L want to go another page when I click a row in crystal report

suppose I have 100 row in my report n when I click  a Row I want to go detail page is it possible

please help me

priya_pooja12324@yahoo.co.in

Reply | Email | Delete | Modify | 
Cystal Report direct printing by akila On March 20, 2007
hi, Printtoprinter method is printing on serverside.But I want to print directly on client side printer.it is very urgent.Please help me.I need to print from web based POS BIll system. Thanks, Akila
Reply | Email | Delete | Modify | 
Re: Cystal Report direct printing by captain On July 24, 2007

Hi,

 

I have to do the same thing. Please let me know if you solved your problem and got success in printing Crystal Report Client Side.

 

Thanks a lot in advance

Reply | Email | Delete | Modify | 
Re: Cystal Report direct printing by riyaz On November 6, 2007
hi akila I have to do the same thing. Please let me know if you solved your problem and got success in printing Crystal Report Client Side thanks
Reply | Email | Delete | Modify | 
doubt in crystal report by shylaja On March 22, 2007
how to connect from gridview to crystalreport directly thatmeans we are adding columns in gridview dynamically so with those columns we have to generate crystal report dynamically
Reply | Email | Delete | Modify | 
Re: doubt in crystal report by Mahesh On March 22, 2007
I don't think you can connect a GridView with Crystal Report. You will have to add that column to your DataSet, which has data in it dynamically and pass that to the report.
Reply | Email | Delete | Modify | 
How to print crytal reports from client side by suresh On April 12, 2007
hi i am suresh, i need to print crystal report from web page.
Reply | Email | Delete | Modify | 
Re: How to print crytal reports from client side by Mahesh On April 13, 2007
Isn't this article shows how to print a report from a Web page?
Reply | Email | Delete | Modify | 
Printing report from crystal report withouth print dialog by nupur On April 27, 2007
how will i do this for windows based application? Please provide me the solution i need it urgently
Reply | Email | Delete | Modify | 
Re: Printing report from crystal report withouth print dialog by Mahesh On April 27, 2007
The code will be same for Windows application as well.
Reply | Email | Delete | Modify | 
I want to set Paper Type eg. Fanfold 15 X 12 in for all report by Munish On May 14, 2007
Is it possible to set Paper Style in Crystal Report through AP.net. I want to set Paper Type eg. Fanfold 15 X 12 in for all report.
Reply | Email | Delete | Modify | 
What are the required namespace? by dan On June 8, 2007
Hi Mr. Mahesh. May I know what are the namespace I need to include? Coz I have the following errors - 1. Dim DS As DataSet = GetData() -Name GetData is not declared 2. MyReport does not appear on the intellisense. Thanks
Reply | Email | Delete | Modify | 
Re: What are the required namespace? by Mahesh On June 21, 2007

MyReport is the report you created as rpt file and added to your proejct.

GetData is my own method that returns the data from the database in a DataSet format. You have to write this method to get the data from the database.

Reply | Email | Delete | Modify | 
Print directly to printer(Without Spooling) by shirish On August 1, 2007
Hi I am currently working on a VB.NET project with following requirements : Suppose I have to print .doc file having 10 pages using VB.Net program and after clicking on print button,suppose printer finishes printing 6 pages and then suddenly printer is out of papaer/light is off ,etc. then if I check the printer properties then it should not show remaining 4 pages in the queue. i.e. Generally what happens is that first 10 pages are taken into buffer of printer and then printing starts. But problem is that if printing operation stops due to some reason, then remaining pages will be in buffer. So I dont want that all pages should be in buffer.I want to print these pages one by one, so that if printing is stopped due to some reason then there should be no pages in queue. So how it can be done using vb.net programming
Reply | Email | Delete | Modify | 
Print last page from Crystal report by partha On August 3, 2007
Hello experts.. Please help me.. I need to print last page of data using Crystal Report. Please reply me have any idea as soon as possible. Thank you
Reply | Email | Delete | Modify | 
how to print crystalreport in web site by atiyeh On August 19, 2007
i want to print report with print Button in web site but when i click this button show java script error why? please help mi. thanks
Reply | Email | Delete | Modify | 
Re: how to print crystalreport in web site by Antony On October 9, 2007

Hi....

on Clicking Print _ Btn

We can Open the Crystal Report in aPdf File Format and from there we can print the Crystal report

coding:

Dim Crpt As CrystalTestReport2

Dim MyTable As CrystalDecisions.CrystalReports.Engine.Table

Dim MyLogin As CrystalDecisions.Shared.TableLogOnInfo

 

Dim oStream As New System.IO.MemoryStream

Crpt = New CrystalTestReport2

Crpt.PrintOptions.PaperSize = PaperSize.PaperA4

Crpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape

 

CrystalReportViewer1.ReportSource = Crpt

For Each MyTable In Crpt.Database.Tables

MyLogin = MyTable.LogOnInfo

MyLogin.ConnectionInfo.UserID = "sa"

MyLogin.ConnectionInfo.Password = ""

MyTable.ApplyLogOnInfo(MyLogin)

Next

 

 

Dim ReportDiskDestination As New CrystalDecisions.Shared.DiskFileDestinationOptions

Dim FileName As String = "c:\TestPDF\myreport2.pdf"

ReportDiskDestination.DiskFileName = FileName

With Crpt

.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile

.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat

.ExportOptions.DestinationOptions = ReportDiskDestination

.Export()

End With

Response.Redirect("c:\TestPDF\myreport2.pdf")

Reply | Email | Delete | Modify | 
crystal report client side printing by riyaz On November 6, 2007
hi have u finish the client side printing successfully if means can u send the method to me??? i hope soon regards riyaz
Reply | Email | Delete | Modify | 
Asp.net Crystal report , Load report failed error by Mehul On November 7, 2007
Hi Mahesh, I am getting error of Load report failed when I try to access crystal report using my asp.net application, can you give me one solution.
Reply | Email | Delete | Modify | 
vs2005 c# ans cr with parameter by a On January 11, 2008
Hi , Using VS 2005 with integrated crystalreport On my computer is good developer parameters can be taken into consideration. But when I deploys on a client with clickonce I get an error on the reports with parameters Thanks
Reply | Email | Delete | Modify | 
print the current value of a wenb page in crystal report by Shashank On October 22, 2008
hi, I m shashank, my problem is that I want to print current values of web page in the form of bill by using the crystal report and also want to add the same values in the database by clicking the single button please help me........
Reply | Email | Delete | Modify | 
crystal report by sapna On June 1, 2009

 Hello All of You,

I am sapna,I have problem of print crystal report on server .when i Click on print option it is not tak any action

please help me

goldsapna@gamil.com

Reply | Email | Delete | Modify | 
How to print a crystal report from client side? by Sri On June 25, 2009
Hi All,
Do you have any snippet code to print crystal report in client side?
Thanks.
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved