Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Tip: How to Print a Crystal Report Programmatically in ASP.NET?
WhatsApp
Mahesh Chand
4y
317.9k
0
7
100
Article
You can print a Crystal Report using the print option of Crystal Report Viewer. However, there are occasions when you want your application to print a report directly to the 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:
Add a crystal report (.cr) file to your ASP.NET application.
Add a report instance on the page level.
Dim report As MyReport = New MyReport
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)
Print Report
report.PrintToPrinter(1, False, 0, 0)
If you wish to print a certain page range, change the last two parameters From 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
CR
Crystal Reports
Print
Print directly
printing crystal reports
PrintToPrinter
Up Next
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.
Membership not found