WPF:以PDF格式呈现报告

时间:2015-02-04 09:44:15

标签: wpf rdlc wpf-4.0

我正在使用WPF rdlc,目前我使用windowformhost reportviewer来显示我的报告。如果我需要以PDF格式查看,我将通过单击导出按钮通过报告查看器导出为PDF。

无论如何直接以PDF格式显示报告而不是执行上述所有步骤?

我使用VS2013作为开发工具

谢谢

1 个答案:

答案 0 :(得分:0)

是的,这是可能的。您希望首先使用ReportViewer呈现报表,然后将其流式传输到文件。一旦将其写入文件,您就可以从文件系统中打开pdf。

出口就是这样的:

byte[] renderedBytes = rptViewer.LocalReport.Render(
    "PDF",
    "<DeviceInfo><ExpandContent>True</ExpandContent></DeviceInfo>",
    out mimeType,
    out encoding,
    out fileNameExtension,
    out streams,
    out warnings);

using (FileStream fsExport = new FileStream(@"C:\MyLocation\MyReport.pdf", FileMode.Create))
{
    fsExport.Write(wordbytes, 0, wordbytes.Length);
}

现在您只需打开pdf文件:

System.Diagnostics.Process.Start(@"C:\MyLocation\MyReport.pdf")