C# 将SSRS的输出以PDF格式直接发送到打印机

C# 将SSRS的输出以PDF格式直接发送到打印机,c#,printing,ssrs-2008,C#,Printing,Ssrs 2008,我正在尝试从SSRS导出获取输出,并将其直接发送到服务器端打印机,而无需调用打印对话框 ReportingService.ReportExporter.Export("basicHttpEndpoint", new NetworkCredential("userNmae", "*********"), reportName, parameters.ToArray(), reportFormat, out output, out extension, out mimeType, out encod

我正在尝试从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\u打印页面
在web和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;
}
private void pd_PrintPage(对象发送方,PrintPageEventArgs ev)
{
float linesPerPage=0;
浮动yPos=0;
整数计数=0;
浮动左边距=ev.MarginBounds.Left;
浮动顶部边距=ev.MarginBounds.Top;
字符串行=null;
//计算每页的行数。
linesPerPage=ev.MarginBounds.Height/
printFont.GetHeight(ev.Graphics);
//打印文件的每一行。
而(计数<行数页&&
((line=streamToPrint.ReadLine())!=null))
{
yPos=topMargin+(计数*
printFont.GetHeight(ev.Graphics));
ev.图形.抽绳(线条,打印字体,画笔.黑色,
leftMargin、yPos、新StringFormat());
计数++;
}
//如果存在更多行,请打印另一页。
如果(行!=null)
ev.HasMorePages=true;
其他的
ev.HasMorePages=false;
}

我无法获得数据的格式,它只是将图像数据打印为字符。是否需要将输出数据转换为其他格式?

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