WPF :以 PDF 格式呈现报表



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

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

我正在使用VS2013作为开发工具

谢谢

是的,这是可能的。您希望首先使用报表查看器呈现报表,然后将其流式传输到文件。将其写入文件后,您可以从文件系统中打开 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:MyLocationMyReport.pdf", FileMode.Create))
{
    fsExport.Write(wordbytes, 0, wordbytes.Length);
}

现在您只需打开 pdf 文件:

System.Diagnostics.Process.Start(@"C:MyLocationMyReport.pdf")

最新更新