在asp.net中显示PDF的方法:

来源:http://www.cnblogs.com/tengs2000/archive/2009/02/23/1396646.htmlhtml

 

1、直接显示,使用的仍是原页面的URLapp

1 Response.ContentType = "application/pdf";
2 Response.Clear();
3 Response.TransmitFile(@"SharePoint.pdf");
4 Response.End();
C# Code

 

2、以PDF文件作为URL进行显示ide

Response.Redirect("Sharepoint.pdf");spa

 

3、点击进行下载.net

1 Response.ClearHeaders();
2 Response.ContentType = "application/pdf";
3 Response.Clear();
4 Response.AppendHeader("Content-Disposition", "attachment;Filename=SharePoint.pdf");
5 Response.TransmitFile(@"SharePoint.pdf");
6 Response.End();

 

注意:上面SharePoint.pdf是pdf文件的名字与路径。(如今是当前目录,故目录没有写“ ./ ” 而已。)code

 

4、在一个页面中嵌入一个PDF显示框server

例如:在Default4.aspx里面显示一个框,能够使用iframe。htm

<iframe runat ="server" src="getPdfFile.aspx?filename=./pdf/通知.pdf" width="800px" height="600px" ></iframe>blog

另外再写一个getPdfFile.aspx页面,写其pageload事件:事件

1 protected void Page_Load(object sender, EventArgs e)
2     {
3         string fileName = Request["fileName"];
4         Response.ContentType = "application/pdf";
5         Response.Clear();
6         Response.TransmitFile(@""+fileName);
7         Response.End();
8     }

嗯,这个作法是参考了http://bbs.csdn.net/topics/340192312里面的讨论。

但是拷贝别人的代码过来,运行不了,只好用了上面第一种的作法。(可能不是很好。)

原来的代码: