将SSRS的输出作为PDF直接发送到打印机

时间:2012-10-09 20:35:11

标签: c# printing ssrs-2008

我正在尝试从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_PrintPage已在网络和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;
}

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

1 个答案:

答案 0 :(得分:0)

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

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

Printing a PDF in c# using a stream ... can it be done ?