查看PDF作为页面的一部分 [英] View PDF as part of the page

查看:164
本文介绍了查看PDF作为页面的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的MVC网页,查看PDF文档,但我不能让它工作。

我想显示的PDF作为页面上其他的东西的一部分(页眉,页脚等)。目前,我有其中显示的PDF解决方案,而是整个页面上。

有没有人做到了这一点,如果是的话怎么办?


解决方案

你为什么不尝试使用iframe的是这样的:

 < IFRAME SRC =即使文件流动作URL>< / IFRAME>


  

我建议使用对象标记,如果有可能,使用iframe只是为了测试。


如果您想渲染PDF作为你只是做了页面的一部分


  

SRC ='&下;%Html.RenderAction(GetPDF); %>


然后,这是你的选择。

如果您在使用CSS或任何,像谷歌书籍等需要对PDF内容完全控制,那么你需要的工具,帮助您以PDF的每个请求页面转换为纯文本,HTML,甚至图像。
工具,如PDFsharp。
谷歌搜索工具

如果你想显示PDF作为页面的一部分,那么这是你必须做的事情。

  ASPX:SRC =<%= Url.Action(GetPDF)%>中
剃刀:SRC =@ Url.Action(GetPDF)

和最终的答案可能是

 <对象数据=<%= Url.Action(GetPDF)%>中类型=应用/ PDFWIDTH =300HEIGHT =200>
    中高音:其中; A HREF =数据/检验.pdf>检验.pdf&下; / A>
< /对象>

和在你想返回PDF作为流的情况下,那么你需要

 公共FileStreamResult GetPDF()
{
    的FileStream FS =新的FileStream(C:\\\\ PeterPDF2.pdf,FileMode.Open,FileAccess.Read);
    返回文件(FS,应用程序/ PDF格式);
}

I am trying to view a PDF document in my MVC web page, but I cant make it to work.

I would like the PDF to be displayed as a part of the other stuff on the page (header, footer etc.). Currently I have a solution where the PDF is shown, but on the entire page.

Has anybody done this, if yes then how?

解决方案

Why don't you try using iframe like this :

<iframe src="even file stream action url"></iframe>

I suggest to use object tag if it's possible, use iframe just for testing.

If you want to render PDF as part of the page as you just did

src='<% Html.RenderAction("GetPDF"); %>'

Then this is your option

If you need complete control over PDF content using CSS or whatsoever, like Google books and so on, then you need tools that help you to convert each requested page of PDF to Plain Text, HTML or even image. tools like PDFsharp. Search Google For Tools

If you want display PDF as part of the page then this is what you have to do

ASPX: src="<%= Url.Action("GetPDF") %>"
Razor: src="@Url.Action("GetPDF")"

And final answer could be

<object data="<%= Url.Action("GetPDF") %>" type="application/pdf" width="300" height="200">
    alt : <a href="data/test.pdf">test.pdf</a>
</object>

And in the case that you want to return PDF as Stream then you need

public FileStreamResult GetPDF()
{
    FileStream fs = new FileStream("c:\\PeterPDF2.pdf", FileMode.Open, FileAccess.Read);
    return File(fs, "application/pdf");
}

这篇关于查看PDF作为页面的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆