0

我正在尝试从 SSRS 导出中获取输出并将其直接发送到服务器端打印机而不调用打印对话框

ReportingService.ReportExporter.Export("basicHttpEndpoint", new NetworkCredential("userNmae", "*********"), reportName, parameters.ToArray(), reportFormat, out output, out extension, out mimeType, out encoding, out warnings, out streamIds);

在这种情况下,导出类型是图像;我正在尝试获取输出(这是一个字节数组)并设置一个内存流,然后尝试使用PrintDocumen()如下方式直接打印

Stream stream = new MemoryStream(output);
StreamReader streamToPrint = new StreamReader(stream);

var pd = new PrintDocument();
pd.PrintPage += pd_PrintPage;
pd.PrintController = new StandardPrintController();
pd.Print();

pd_PrintPageweb 和 MSDN 上有很好的记录

private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
  float linesPerPage = 0;
  float yPos = 0;
  int count = 0;
  float leftMargin = ev.MarginBounds.Left;
  float topMargin = ev.MarginBounds.Top;
  string line = null;

  // Calculate the number of lines per page.
  linesPerPage = ev.MarginBounds.Height /
     printFont.GetHeight(ev.Graphics);

  // Print each line of the file. 
  while (count < linesPerPage &&
     ((line = streamToPrint.ReadLine()) != null))
  {
      yPos = topMargin + (count *
         printFont.GetHeight(ev.Graphics));
      ev.Graphics.DrawString(line, printFont, Brushes.Black,
         leftMargin, yPos, new StringFormat());
      count++;
  }

  // If more lines exist, print another page. 
  if (line != null)
      ev.HasMorePages = true;
  else
      ev.HasMorePages = false;
}

我无法获取数据的格式,它只是将图像数据打印为字符。我需要将输出数据转换为另一种格式吗?

4

1 回答 1

0

因为您告诉打印命令将字节作为文本而不是呈现输出。为了将流渲染到打印机,您需要一个 PDF 打印驱动程序(例如 Acrobat)。以下是一些选项:

https://stackoverflow.com/questions/8338953/print-in-memory-pdf-without-saving-directly-without-a-printer-dialog-or-user-i

使用流在 c# 中打印 PDF ...可以完成吗?

于 2012-10-09T20:41:58.443 回答