RDLC不直接打印 [英] RDLC is not directly printing

查看:129
本文介绍了RDLC不直接打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在使用在线结算软件。在这里,我使用rdlc作为账单。我的问题是,当rdlc打开时,直接打印请求正在发送给打印机。整个功能在localhost上运行正常。但是当我在网上检查时,直接打印请求无效。



这是我的代码:





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:


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

推荐答案

您的代码在本地工作,因为在这种情况下,SERVER和CLIENT机器是相同的!使用服务器端c#代码进行打印的代码将无法在您的网站发布到实时Web服务器的实际场景中工作,该实时Web服务器不会(当然)与普通用户用于访问您的站点和打印的机器相同。

您必须使用浏览器供应商提供的javascript打印功能打印RDLC(只需google for window.print)或尝试其中一些替代方案:



在ASP中自动打印RDLC文件。 NET MVC 3 [ ^ ]



如何在没有预览或打印机对话框的情况下打印ASP.NET本地报表RDLC [ ^ ]



http://stackoverflow.com/questions/951009/sql-reporting-services-print-button-not-shown-in-mozilla [ ^ ]
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[^]


这篇关于RDLC不直接打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆