问题描述
我有我的网站到位的解决方案呈现在使用下面的code一整页的请求的PDF文档。现在我的客户希望有一个iframe中呈现的文档。我似乎无法得到它的工作很容易,也许我失去了一些东西明显。第一code将正常在新窗口中显示PDF。
I have a solution in place for my site that renders a requested PDF document in a full page using the code below. Now my client wants the document rendered within an iframe. I can't seem to get it to work readily, maybe I am missing something obvious. The first code will properly display the PDF in a new window.
if (File.Exists(filename))
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
Response.WriteFile(filename);
Response.End();
}
else Response.Write("Error - can not find report");
iframe的code是这样的:
The iframe code looks like this:
<iframe runat="server" id="iframepdf" height="600" width="800" > </iframe>
我知道我应该使用src属性的文件名,但问题似乎是Page_Load事件触发之前的iframe负荷,因此未创建PDF文件。有什么明显的我失踪?
I know I am supposed to use the src attribute for the filename, but the problem seems to be that the iframe loads before the Page_Load event fires, so the PDF is not created. Is there something obvious I am missing?
推荐答案
使用一个ASHX处理程序。该人士$ C $ C你getmypdf.ashx.cs处理程序应该是这个样子:
Use an ASHX handler. The source code to your getmypdf.ashx.cs handler should look something like this:
using System;
using System.Web;
public class getmypdf : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Response.ContentType = "Application/pdf";
Response.WriteFile("myfile.pdf");
Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
getmypdf.ashx将包含这样的:
getmypdf.ashx would contain something like this:
<% @ webhandler language="C#" class="getmypdf" %>
和您的iframe是这样的:
And your iframe would look like this:
<iframe runat="server" id="iframepdf" height="600" width="800" src="..../getmypdf.ashx"> </iframe>
这篇关于在iframe中显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!