在ASP.net中打印RDLC报告,而不在客户端进行预览

本文关键字:客户端 net ASP 打印 RDLC 报告 | 更新日期: 2023-09-27 18:26:33

我有一个RDLC报告,当它在Visual Studio中运行时,它会在本地打印良好。当我上传我的项目到服务器它不会打印。我做了一些研究,了解到当项目在服务器上时,它会尝试在服务器上打印,而不是在客户端机器上。现在有人知道如何在客户端机器上打印吗?

   private Stream CreateStream(string name, string fileNameExtension, Encoding encoding,         string mimeType, bool willSeek)
    {
        Stream stream = new MemoryStream();
        m_streams.Add(stream);
        return stream;
    }
    private void Export(LocalReport report)
    {
        string deviceInfo =
          "<DeviceInfo>" +
          "  <OutputFormat>EMF</OutputFormat>" +
          "  <PageWidth>8.5in</PageWidth>" +
          "  <PageHeight>11in</PageHeight>" +
          "  <MarginTop>0.01in</MarginTop>" +
          "  <MarginLeft>0.02in</MarginLeft>" +
          "  <MarginRight>0.25in</MarginRight>" +
          "  <MarginBottom>0.25in</MarginBottom>" +
          "</DeviceInfo>";
        Warning[] warnings;
        m_streams = new List<Stream>();
        report.Render("Image", deviceInfo, CreateStream, out warnings);
        foreach (Stream stream in m_streams)
        {
            stream.Position = 0;
        }
    }
    private void PrintPage(object sender, PrintPageEventArgs ev)
    {
        Metafile pageImage = new Metafile(m_streams[currentPageIndex]);
        ev.Graphics.DrawImage(pageImage,ev.PageBounds);
        currentPageIndex++;
        ev.HasMorePages = (currentPageIndex < m_streams.Count);
    }

    private void Print_Ticket()
    {
        const string printerName = "HP DeskJet";
        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);
            Console.WriteLine(msg);
            return;
        }
        printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
        printDoc.Print(); //Prints Document
    }
    public void WriteTicket(string ticket_number, string queue)
    {
        LocalReport report = new LocalReport();
        //Displays ticket letter and number in ticket
        report.ReportPath = "PrintTicket.rdlc";
        ReportParameter ticket_parameter = new ReportParameter();
        ticket_parameter.Name = "Ticket";
        ticket_parameter.Values.Add(ticket_number);
        report.SetParameters(new ReportParameter[] { ticket_parameter });
        //Displays date and time in ticket
        ReportParameter date = new ReportParameter();
        date.Name = "Date_Time";
        date.Values.Add(System.DateTime.Now.ToString());
        report.SetParameters(new ReportParameter[] { date });
        //Displays branch location in ticket
        ReportParameter location_parameter = new ReportParameter();
        location_parameter.Name = "Location";
        location_parameter.Values.Add(queue);
        report.SetParameters(new ReportParameter[] { location_parameter });
        Export(report);
        currentPageIndex = 0;
        Print_Ticket();
    }
    //Clears stream
    public new void Dispose()
    {
        if (m_streams != null)
        {
            foreach (Stream stream in m_streams)
                stream.Close();
        }
    }

在ASP.net中打印RDLC报告,而不在客户端进行预览

我一直在应用程序中使用ReportViewer控件。这可以在客户端机器上打印查看的报告。我想你可以使用这个控件做同样的事情,即使它不可见,如果这是你想要实现的。

如果这没有帮助的话。此链接可能有用。http://msdn.microsoft.com/en-us/library/ms252091.aspx