【问题标题】:Open Pdf in a new tab using jQuery使用 jQuery 在新选项卡中打开 Pdf
【发布时间】:2012-12-05 00:26:55
【问题描述】:

我的 MVC4 Actionresult 返回一个 MemoryStream

MemoryStream memory = new MemoryStream();
Response.AppendHeader("Content-Disposition", "inline; filename=" + outputFilename + ".pdf");
            return File(memory, "application/pdf"); 

还有 Jquery

$.ajax({
            type: "GET",
            url: '/Report/Pdf/',
            async: false,
            dataType: 'html',
            success: function (result) { alert("Done!");}
        });

如何在 AJAX 的成功功能上打开新窗口/标签并显示 PDF 文件?

【问题讨论】:

  • 为什么需要为此使用 Ajax?为什么不直接使用链接,location.href = "xyz"window.open()
  • 确实,我相信你想要 window.open<iframe> 如果你想嵌入它。
  • @Pekka - 是的..愚蠢的我!谢谢..那行得通..

标签: jquery asp.net-mvc-4 pdf-generation


【解决方案1】:

最简单的方法是使用链接,有或没有target=blank(前者将允许用户自己控制他们想要打开它的位置)。

 <a href="/Report/pdf">

然后是window.open,但据我所知,您不能直接使用它来定位新标签。

【讨论】:

  • -有没有办法将内存流转换为图像?
  • @Gokul 在浏览器端?几乎不。我认为您需要为此提供服务器端解决方案
  • 好的.. 将图像保存在服务器端并在 HTML 中调用它.. 感谢您的帮助。
  • @Nips 我看不出它为什么不应该这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-18
  • 2018-12-05
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
  • 2015-09-10
相关资源
最近更新 更多