我正在尝试从 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
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;
}
我无法获取数据的格式,它只是将图像数据打印为字符。我需要将输出数据转换为另一种格式吗?