http://www.csdn.net/develop/MY_article.asp?author=haibodotnet

解决方案 »

  1.   

    /* ****************************************************
    Title: Using Client-Side Printing FeaturesCreated: December 23 2003 
    Author: JAS
    Copyright: Business Objects 2003Purpose:
    This sample C# ASP.NET Web application demonstrates how 
    to use the viewer's PrintMode property to specify how
    client-side printing is to function.  The PrintMode property allows client-side printing using
    a PDF solution, or an ActiveX control solution.?The PDF solution involves displaying a pop-up browser window
    with Print options to select the page range to print.  
    Once the page range is selected and the Print button is clicked, 
    the report is exported to PDF format on the server, and
    streamed back to the client and displayed in the pop-up 
    browser window.?The ActiveX solution involves downloading and installing 
    a small client-side ActiveX control that will display a
    Print dialog that contains the printer drivers configured
    on the client's machine.  Once a printer is selected, the
    report is printed to that printer.  A small window displays
    the status of the report being printed.NOTES:
    The following are known issues with this sample application:?When using the ActiveX option, the small pop-up window 
    cannot be disabled or modified.?The ActiveX solution requires a postback for each
    page being printed.
    ***************************************************** */using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;//Specify the Crystal Decisions namespace
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;namespace csWeb_ClientPrinting
    {
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    //Define local ReportDocument variable.
    private ReportDocument reportDocument; //These variables are auto-generated.
    protected System.Web.UI.WebControls.Panel Panel2;
    protected System.Web.UI.WebControls.RadioButton radActiveX;
    protected System.Web.UI.WebControls.RadioButton radPDF;
    protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
    protected System.Web.UI.WebControls.Button butPreviewReport;
    protected System.Web.UI.WebControls.Label lblClickPrintButton;
    protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer2;
    protected System.Web.UI.WebControls.Label lblPrintTypeDescription;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    //Do nothing
    }
    else  //for each post-back...
    {
    //Display the label control that displays a description for each PrintMode type
    lblPrintTypeDescription.Visible = true; //Once a PrintMode type is selected, enable the Preview button.
    butPreviewReport.Enabled = true; //Because the RadioButton controls have set the AutoPostBack to true, their
    //CheckChanged event is disabled.  The PostBack event is used to check each 
    //RadioButton and set the PrintMode type for the viewer.  This 'if...else' 
    //statement will set the appropriate PrintMode for the viewer and display
    //the description for each PrintMode type.
    if (radActiveX.Checked == true)
    {
    //这个是Crystal官方的web打印示例程序,程序是.Net1.0(vs2002)下写的
    //有PrintMode这个属性 可以指定用ActiveX或者pdf打印 没有dhtml的 :(
    //.Net1。1的CrystalReportViewer却没有PrintMode这个属性 :(
    //那么该如何打印? CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
    lblPrintTypeDescription.Text = "This option will download a small client-side ActiveX control that will display the client machine's Print dialog.  The user can select a printer to print to and the report will be printed to that printer on the client machine.";
    }
    else //(radPDF.Checked == true)
    {
    CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf;
    lblPrintTypeDescription.Text = "This option will display a popup browser window to select print options and then display the report in the same window as a Portable Document Format (PDF) file.";
    }

    //If the report has been previewed once, the ReportSource needs to be
    //set on each postback.  When the Preview Report button is first clicked,
    //it loads the report, binds it to the viewer, and puts the ReportDocument 
    //object into a Session varable.  This code pulls that ReportDocument object
    //from Session and reassigns the viewer's ReportSource, for each postback.
    if (Session["REPORT"] != null)
    {
    reportDocument = (ReportDocument)Session["REPORT"];
    CrystalReportViewer1.ReportSource = reportDocument;
    }
    }

    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.butPreviewReport.Click += new System.EventHandler(this.butPreviewReport_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    private void butPreviewReport_Click(object sender, System.EventArgs e)
    {
    //Create a new instance of the ReportDocument class
    reportDocument = new ReportDocument(); //Load the sample World Sales Report, which has been added to this project
    reportDocument.Load(Server.MapPath("World Sales Report.rpt")); //Set the ReportDocument object to the viewer's ReportSource
    CrystalReportViewer1.ReportSource = reportDocument; //The ReportDocument object will need to placed into Session so that
    //on each postback, the viewer's ReportSource can be set to this instance
    Session.Add("REPORT", reportDocument); //Once the report has been displayed, hide the Preview Report button
    butPreviewReport.Visible = false; //Display a message to the user to click on the Print button in the toolbar
    lblClickPrintButton.Visible = true;
    }
    }
    }
      

  2.   

    直接用CRYSTALREPORT打印不就行了吗?