如何从外部链接打开/预览pdf文件?

时间:2016-05-01 20:26:30

标签: asp.net-mvc asp.net-mvc-4 pdf razor

我只是想知道如何使用外部在线(在我的网站上)打开pdf文件。实际上我尝试了文件流,但没有得到任何结果...

例如我在我的视图中有这个pdf文件链接:

suites:
  - name: default
    run_list:
      - recipe[mycookbook::default]
    data_bags_path: "test/integration/data_bags" 
    attributes:
      authorization:
        sudo:
          passwordless: true
          users: ['vagrant']

这是我的控制器代码:

<a class="btn btn-block btn-lg btn-info" href="@Url.Action("Preview1", "book")" target="_blank" rel="nofollow" itemprop="url">Preview Book <i class="fa fa-file-pdf-o"></i></a>

我收到了这个错误:

[HttpGet]
    public ActionResult Preview1()
    {


            var fileStream = new FileStream("http://www.pdf995.com/samples/pdf.pdf",
                                          FileMode.Open,
                                          FileAccess.Read
                                      );
            return new FileStreamResult(fileStream, "application/pdf");

    }

1 个答案:

答案 0 :(得分:0)

如果它在网络上,请让它有一个网络内容。

WebClient client = new WebClient();
var fileStream = client.OpenRead("http://example.com/file.pdf");

访问 WebClient at Microsoft

相关问题