{"id":442,"date":"2008-01-04T18:24:34","date_gmt":"2008-01-05T01:24:34","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/crystal-reports-xi\/3-7-printing-directly-to-the-printer\/"},"modified":"2010-11-17T18:27:58","modified_gmt":"2010-11-18T01:27:58","slug":"3-7-printing-directly-to-the-printer","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/3-7-printing-directly-to-the-printer\/","title":{"rendered":"3.08 Printing Directly to the Printer"},"content":{"rendered":"<h2>Printing Reports Directly to the Printer<\/h2>\n<p>If you decide not to user the viewer control for previewing reports, you will have to write all the code for loading and printing reports. The following sections show you examples of how to instantiate report objects and send their output to the printer.<\/p>\n<p>At this point in the book, the amount of code you need to write is still very limited and it is easy to understand. Once you get into Part II of this book, you&#8217;ll see that this code serves as the foundation for performing advanced runtime customization of your reports.<\/p>\n<h3>Printing Untyped Reports Directly<\/h3>\n<p>Printing Untyped reports without using the viewer requires a bit more coding than the examples you&#8217;ve seen so far. First you must declare and instantiate a ReportDocument object. The ReportDocument object has methods for loading the report into memory and printing it. Call the Load() method and pass it the report&#8217;s filename. Call PrintToPrinter() to send the report to the printer.<\/p>\n<p><code>Private Sub Form1_Load(ByVal sender As System.Object, _<\/code><br \/>\n<code>ByVal e As System.EventArgs) Handles MyBase.Load<\/code><br \/>\n<code>Dim MyReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument<\/code><br \/>\n<code>MyReport.Load(\"Employee List.rpt\")<\/code><br \/>\n<code>MyReport.PrintToPrinter(1, False, 0, 0)<\/code><br \/>\n<code>End Sub<\/code><\/p>\n<p>This example loads the Employee List report in the MyReport object variable. Then it calls the PrintToPrinter() method to print a single copy of the report, including all pages.<\/p>\n<h3>Printing Strongly-Typed Reports Directly<\/h3>\n<p>Printing Strongly-Typed reports is a little easier than printing Untyped reports. With Strongly-Typed reports, the report&#8217;s class name is part of the project and can be instantiate directly. Unlike Untyped reports, you don&#8217;t have to use the generic ReportDocument class and you don&#8217;t have to worry about loading the report from a file. After instantiating the report object, call the PrintToPrinter() method to send it to the printer.<\/p>\n<p><code>Private Sub Form1_Load(ByVal sender As System.Object, _<\/code><br \/>\n<code>ByVal e As System.EventArgs) Handles MyBase.Load<\/code><br \/>\n<code>Dim MyReport As New Employee_List<\/code><br \/>\n<code>MyReport.PrintToPrinter(1, False, 0, 0)<\/code><br \/>\n<code>End Sub<\/code><\/p>\n<p>This declares the object variable MyReport to be of type Employee_List and instantiates it. For your application, use the class name of the report that you want to print. The PrintToPrinter() method prints a single copy of the report.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Printing Reports Directly to the Printer If you decide not to user the viewer control for previewing reports, you will have to write all the code for loading and printing reports. The following sections show you examples of how to instantiate report objects and send their output to the printer. At this point in the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,2],"tags":[],"class_list":["post-442","post","type-post","status-publish","format-standard","hentry","category-chapter-3-integrating-reports","category-crystal-reportsnet-2003","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=442"}],"version-history":[{"count":1,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/442\/revisions"}],"predecessor-version":[{"id":1534,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/442\/revisions\/1534"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=442"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}