cancel
Showing results for 
Search instead for 
Did you mean: 

Print Problem

Former Member
0 Kudos

Hi,  I used CrystalReportViewer in Visual Studio 2013 to show report on Web app.  The report works fine, but when I click "Print" button to print this report, it shows the dialog "Print to PDF" to Export.  How to get "Print" dialog. 

Thank you very much for any idea and help.

Regards,

Qin

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Alternatively, create your own print dialog and place that under your own button:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System.Drawing.Printing;

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        CrystalReport1 cr;

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            ToolStrip ts;

            ts = (ToolStrip)crystalReportViewer1 .Controls[3];

            ToolStripButton printbutton = new ToolStripButton();

            printbutton.Image = ts.Items[1].Image;

            ts.Items.Remove(ts.Items[1]);

            ts.Items.Insert(1, printbutton);

            ts.Items[1].Click += new EventHandler(this.CaptureEvent);                  

            cr = new CrystalReport1();

            this.crystalReportViewer1.ReportSource = cr;

                         

        }

        private void CaptureEvent(Object Sender, EventArgs e)

        {

            try

            {        // Create a Print Dialog                

                PrintDialog printDialog1 = new PrintDialog();

                // Create a Print Document

                PrintDocument pd = new PrintDocument();

                printDialog1.Document = pd;

                printDialog1.ShowNetwork = true;

                printDialog1.AllowSomePages = true;

                DialogResult result = printDialog1.ShowDialog();

                if (result == DialogResult.OK)

                {

                    MessageBox.Show("Print button has been selected !!!");

                    PrintReport(printDialog1.PrinterSettings.PrinterName);

                }

                else if (result == DialogResult.Cancel)

                {

                    MessageBox.Show("Cancel button has been selected !!!");

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

         }

        private void PrintReport(string printerName)

        {

            // Select the printer.

            cr.PrintOptions.PrinterName = printerName;

            /* Print the report. Set the startPageN and endPageN

             parameters to 0 to print all pages.*/

            cr.PrintToPrinter(1, false, 0, 0);

        }                          

    }

}

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Answers (1)

Answers (1)

former_member188030
Active Contributor
0 Kudos

In Visual Studio -  CrystalReportViewer Control properties - set the 'PrintMode' property to 'ActiveX'.

By default the property is set to 'PDF' thats why the print to pdf pops up.

- Bhushan

Senior Engineer

SAP Active Global Support

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Getting started and moving ahead with Crystal Reports .NET applications.

DellSC
Active Contributor
0 Kudos

However, be aware that ActiveX does not work in all browsers.  I think Chrome will automatically use PDF printing.

-Dell