0

我有一个 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();
        }
    }
4

1 回答 1

0

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

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

于 2013-11-01T19:38:01.183 回答