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

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

问题描述

我正在尝试在我的 MVC 网页中查看 PDF 文档,但无法正常工作.

我希望 PDF 显示为页面上其他内容的一部分(页眉、页脚等).目前我有一个显示 PDF 的解决方案,但在整个页面上.

有没有人这样做过,如果是,那么怎么做?

解决方案

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

<iframe src="偶数文件流动作url"></iframe>

<块引用>

如果可能,我建议使用 object 标签,使用 iframe 仅用于测试.

如果您想像刚才那样将 PDF 作为页面的一部分呈现

<块引用>

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

那么这是你的选择

如果您需要使用 CSS 或其他任何方式(例如 Google 图书等)完全控制 PDF 内容,那么您需要一些工具来帮助您将每个请求的 PDF 页面转换为纯文本、HTML 甚至图像.PDFsharp 等工具.在 Google 上搜索工具

如果您想将 PDF 显示为页面的一部分,那么这就是您必须做的

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

最终答案可能是

"type="application/pdf" width="300" height="200">alt:<a href="data/test.pdf">test.pdf</a></对象>

如果您想将 PDF 作为 Stream 返回,那么您需要

public FileStreamResult GetPDF(){FileStream fs = new 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天全站免登陆