代码之家  ›  专栏  ›  技术社区  ›  Saif

如何在asp。net在pdf Direct中打开?

  •  1
  • Saif  · 技术社区  · 8 年前

    我有一个100%工作的ReportViewer,但我需要它以PDF格式直接打开

    这是我的代码示例,我将报告查看器与数据绑定在一起。

    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    ReportDataSource source = new ReportDataSource("dsGetTrnsactions", dt);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(source);
    ReportViewer1.DataBind();
    ReportViewer1.LocalReport.Refresh();
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   erikscandola    8 年前

    您需要获取重新表示PDF文件的字节数组,然后需要打开一个包含PDF文件的新窗口。试试这个:

    byte[] file = ReportViewer1.LocalReport.Render(some parameters);
    
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "inline;filename=Test.pdf");
    Response.Buffer = true;
    Response.Clear();
    Response.BinaryWrite(file);
    Response.End();