将PDF嵌入到二进制数据的MVC视图中

时间:2022-07-23 21:27:21

My issue is I'm currently receiving from a web service response a string that is the binary data of a PDF file. I need to display this PDF file embedded in an MVC view. I'm using C#.

我的问题是我目前正在从Web服务响应中收到一个字符串,它是PDF文件的二进制数据。我需要显示嵌入在MVC视图中的PDF文件。我正在使用C#。

Any pointers are appreciated.

任何指针都表示赞赏。

2 个解决方案

#1


1  

You can just return it using File. Something like this:

你可以使用File返回它。像这样的东西:

public ActionResult ShowPDF()
{
  byte[] pdf = myService.GetPDF();
  return File(pdf, "application/pdf");      
}

UPDATE

UPDATE

Create a page containing a iframe element and set the src attribute to point to your view that renders the PDF file. Here is an example taken from here

创建一个包含iframe元素的页面,并将src属性设置为指向呈现PDF文件的视图。这是一个从这里得到的例子

<iframe src="ShowPDF" width="100%" style="height:20em">

 [Your browser does <em>not</em> support <code>iframe</code>,
 or has been configured not to display inline frames.
 You can access <a href="ShowPDF">the document</a>
 via a link though.]

</iframe>

#2


0  

HTML5 has added the embed tag which allows a variety of rich content to be embedded into the page as follows:<embed src="your file path here" type="application/pdf" />

HTML5添加了embed标签,允许将各种丰富的内容嵌入到页面中,如下所示:

#1


1  

You can just return it using File. Something like this:

你可以使用File返回它。像这样的东西:

public ActionResult ShowPDF()
{
  byte[] pdf = myService.GetPDF();
  return File(pdf, "application/pdf");      
}

UPDATE

UPDATE

Create a page containing a iframe element and set the src attribute to point to your view that renders the PDF file. Here is an example taken from here

创建一个包含iframe元素的页面,并将src属性设置为指向呈现PDF文件的视图。这是一个从这里得到的例子

<iframe src="ShowPDF" width="100%" style="height:20em">

 [Your browser does <em>not</em> support <code>iframe</code>,
 or has been configured not to display inline frames.
 You can access <a href="ShowPDF">the document</a>
 via a link though.]

</iframe>

#2


0  

HTML5 has added the embed tag which allows a variety of rich content to be embedded into the page as follows:<embed src="your file path here" type="application/pdf" />

HTML5添加了embed标签,允许将各种丰富的内容嵌入到页面中,如下所示: