我在不使用 ReportViewer 控件的情况下呈现 SSRS 报告,最近使用的是 LocalReports。您可以在代码中配置 ReportViewer,强制它生成 PDF,并获取 PDF 的字节流。我停在那里并将PDF呈现到我的一组要求的屏幕b / c上,但我确信找到一种打印PDF文件字节流的方法要容易得多,然后处理任何与报告查看器。
以下是如何将 LocalReport 转换为 PDF 文件的字节数组:
LocalReport lclRpt = new LocalReport();
//Do Stuff like bind DataSources, ReportParameters, SubReportProcessing Delegates, etc.
string strMIMEType = String.Empty;
string strEncoding = String.Empty;
string strFileNameExtension = string.Empty;
string[] strarrStreams;
Warning[] warnLocalReportWarnings;
byte[] bytarrPDF = lclRpt.Render("PDF", "<DeviceInfo><StartPage>0</StartPage></DeviceInfo>", out strMIMEType, out strEncoding, out strFileNameExtension, out strarrStreams, out warnLocalReportWarnings);
return bytarrPDF;
我不是 100% 知道如何完成您的最后一步,可能需要一个 .pdf 实用程序,或者可能有一种方法可以直接从代码中完成。