Click here to Skip to main content
14,935,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am working on an online billing software. here, i am using rdlc for bill. My problem is, when rdlc is opening then a direct print request is sending to printer. the whole functionality is working fine on localhost. but when i checked it online then direct printing request is not working.

Here is my code:


XML
private int m_currentPageIndex;
private IList<Stream> m_streams;
private Stream CreateStream(string name,
  string fileNameExtension, Encoding encoding,
  string mimeType, bool willSeek)
{
    Stream stream = new MemoryStream();
    m_streams.Add(stream);
    return stream;
}
// Export the given report as an EMF (Enhanced Metafile) file.
private void Export(LocalReport report, bool isLandscape)
{
    string deviceInfo = string.Empty;
    if (isLandscape)
    {
        deviceInfo =
           @"<DeviceInfo>
            <OutputFormat>EMF</OutputFormat>
            <PageWidth>11in</PageWidth>
            <PageHeight>8.5in</PageHeight>
            <MarginTop>0.25in</MarginTop>
            <MarginLeft>0.25in</MarginLeft>
            <MarginRight>0.25in</MarginRight>
            <MarginBottom>0.25in</MarginBottom>
        </DeviceInfo>";
    }
    else
    {
        deviceInfo =
        @"<DeviceInfo>
            <OutputFormat>EMF</OutputFormat>
            <PageWidth>8.5in</PageWidth>
            <PageHeight>11in</PageHeight>
            <MarginTop>0.25in</MarginTop>
            <MarginLeft>0.25in</MarginLeft>
            <MarginRight>0.25in</MarginRight>
            <MarginBottom>0.25in</MarginBottom>
        </DeviceInfo>";
    }
    Warning[] warnings;
    m_streams = new List<Stream>();
    DSBillTableAdapters.DataTable1TableAdapter ds = new DSBillTableAdapters.DataTable1TableAdapter();
    DSBillTableAdapters.DataTable2TableAdapter ds1 = new DSBillTableAdapters.DataTable2TableAdapter();
    DSBillTableAdapters.NotificationTableAdapter ds3 = new DSBillTableAdapters.NotificationTableAdapter();
    // Create Report DataSource
    ReportDataSource rds = new ReportDataSource("DataSet1");
    ReportDataSource rds2 = new ReportDataSource("DataSet2");
    ReportDataSource rds3 = new ReportDataSource("DataSet3");
    rds.Value = ds.GetData(Convert.ToInt64(Request.QueryString["SaleId"]));
    rds2.Value = ds1.GetData(Convert.ToInt64(Request.QueryString["SaleId"]));
    rds3.Value = ds3.GetData();
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rds);
    ReportViewer1.LocalReport.DataSources.Add(rds2);
    ReportViewer1.LocalReport.DataSources.Add(rds3);
    report.Render("Image", deviceInfo, CreateStream,
       out warnings);
    foreach (Stream stream in m_streams)
        stream.Position = 0;
    Print();
}
private void Print()
{
    PrinterSettings settings = new PrinterSettings(); //set printer settings
    string printerName = settings.PrinterName; //use default printer name

    if (m_streams == null || m_streams.Count == 0)
        return;

    PrintDocument printDoc = new PrintDocument();
    printDoc.PrinterSettings.PrinterName = printerName;
    if (!printDoc.PrinterSettings.IsValid)
    {
        string msg = String.Format(
        "Can't find printer \"{0}\".", printerName);
        MessageBox.Show(msg, "Print Error");
        return;
    }

    printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
    printDoc.Print();
    foreach (Stream stream in m_streams)
    {
        stream.Dispose();

    }

}
private void PrintPage(object sender, PrintPageEventArgs ev)
{
    Metafile pageImage = new
       Metafile(m_streams[m_currentPageIndex]);
    ev.Graphics.DrawImage(pageImage, ev.PageBounds);
    m_currentPageIndex++;
    ev.HasMorePages = (m_currentPageIndex < m_streams.Count);

}

Do anyone has answer for this? If yes then plz reply
Posted
Updated 2-Jun-14 20:42pm
v2

1 solution

Your code is working locally because in that case the SERVER and the CLIENT machines are the same!!! That code that uses server-side c# code for printing will NOT work in real scenarios where your website is published to a live web server which will not be (of course) the same machine that a normal user will use for accessing your site and printing.
You have to print the RDLC using javascript printing functionality provided by browser vendors (just google for window.print) or try some of these alternatives:

Automatically Printing an RDLC file in ASP.NET MVC 3[^]

How to Print an ASP.NET Local Report RDLC without Preview or Printer Dialog[^]

http://stackoverflow.com/questions/951009/sql-reporting-services-print-button-not-shown-in-mozilla[^]
   
Comments
manika.iise 10-Jun-14 5:39am
   
thanks Marc Gabrie......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900