I have a crystal report which i want to print on button click.I have the following code for printing on print button click event
protected void Page_Init(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
}
else
{
if (Session["reportdocument"].ToString() != string.Empty || Session["reportdocument"] != null)
{
ReportDocument reportdocument = (ReportDocument)Session["reportdocument"];
CrystalReportViewer1.ReportSource = reportdocument;
CrystalReportViewer1.DataBind();
}
}
}
protected void ButtonPrint_Click(object sender, EventArgs e)
{
try
{
CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
CrystalReportViewer1.SeparatePages = false;
var printeInstaled = System.Drawing.Printing.PrinterSettings.InstalledPrinters;
string printerName = "";
foreach (var item1 in printeInstaled)
{
printerName = item1.ToString();
break;
}
PrintDocument myPrinter = new PrintDocument();
ReportDocument rptprint = (ReportDocument)Session["reportdocument"];
rptprint.PrintOptions.PrinterName = printerName;
rptprint.PrintToPrinter(1, false, 0, 0);
rptprint.PrintOptions.PaperOrientation = PaperOrientation.DefaultPaperOrientation;
rptprint.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
I am able to disable paging by using CrystalReportViewer1.SeparatePages = false;
But the problem is it prints only first page.In print preview of one note i can see it.And also if i disable paging and try to print pages one by one..it still prints only the first age despite if i am on 2nd or 3rd page.Is this the problem of rebinding report or something?
Why id this happening?Can anyone help me out ?. All these problems i m facing before publishing my app on iis. After publishing the print code is not working at all .