【问题标题】:display a pdf in a modal window without downloaded在不下载的模式窗口中显示 pdf
【发布时间】:2017-12-05 20:55:54
【问题描述】:

我正在尝试在模式窗口中打开 pdf 我遇到了问题

<div class="modal fade" id="basic" tabindex="-1" role="basic" aria- hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria- hidden="true">
                    </button>
      </div>
      <div class="modal-body">
        <iframe id="Iframe1" src="" runat="server" width="540" height="600"></iframe>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn red btn-outline" data- dismiss="modal">
                        أغلق</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
</div>

我给iframe一个src来显示一个pdf文件,

frame1.Attributes.Add("src", "~/file.pdf");

问题是下载管理器强制文件下载而不出现在模式中, 所以我尝试添加下面的代码,但它在所有页面中都打开而不是模式

 string x ="~/file.pdf";

 Response.ContentType = "Application/pdf";
 Response.WriteFile(HttpUtility.HtmlEncode(x));
 Response.End();
 frame1.Attributes.Add("src", x);

【问题讨论】:

    标签: c# asp.net pdf iframe bootstrap-modal


    【解决方案1】:

    您可以做两件事,都与标题中的content-disposition 有关。 关键是用content-dispositioninline返回PDF。

    所以你可以在 IIS 中设置:

    • 转到文件
    • 属性
    • 标题
    • 设置内容处置,内联;文件名="文件1.pdf"

    或者制作你自己的 FileDownloader.aspx。并设置内容配置:

    Response.ContentType = "Application/pdf";
    Response.setHeader("Content-disposition", "inline; filename=\"File1.pdf\"");
    Response.WriteFile(HttpUtility.HtmlEncode("file1.pdf"));
    Response.End();
    

    在您的 iFrame 中,您只需定位下载器

     frame1.Attributes.Add("src", "FileDownloader.aspx");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      相关资源
      最近更新 更多