1、确保要从其上查看 .aspx 页的客户端计算机上已安装了 Adobe Acrobat Reader,以便浏览器能够正确读取并呈现二进制数据。可以从以下 Adobe 网站下载 Adobe Acrobat Reader:
http://www.chinese-s.adobe.com/main.html
(http://www.adobe.com)
2、 确保将您的页面添加到项目中在上一节中添加的 .pdf 文件所在的级别。这一点非常重要,因为代码最初引用 .pdf 文件时采用相对路径。
在代码隐藏页的 Page_Load 事件中,单击“编辑”菜单上的“粘贴”以粘贴代码:
2、 确保将您的页面添加到项目中在上一节中添加的 .pdf 文件所在的级别。这一点非常重要,因为代码最初引用 .pdf 文件时采用相对路径。
在代码隐藏页的 Page_Load 事件中,单击“编辑”菜单上的“粘贴”以粘贴代码:
<!-- .lineBorderBlue1 { BORDER-TOP: #999999 1px groove; BORDER-BOTTOM: #999999 1px groove; BORDER-LEFT: #999999 1px groove; BORDER-RIGHT: #999999 1px groove; background-color:#efefef; } -->
在代码隐藏页的 Page_Load 事件中,加入以下代码:
private
void
Page_Load(
object
sender,System.EventArgse)![]()
...
{ // SettheappropriateContentType. Response.ContentType = " Application/pdf " ; // Getthephysicalpathtothefile. string FilePath = MapPath( " acrobat.pdf " ); // WritethefiledirectlytotheHTTPcontentoutputstream. Response.WriteFile(FilePath); Response.End(); }
|
本文介绍了一种在ASP.NET应用程序中直接显示PDF文件的方法。通过设置正确的MIME类型和使用Response对象来读取指定路径下的PDF文件,使得用户可以直接在浏览器中查看PDF文档而无需下载。



}
1459

被折叠的 条评论
为什么被折叠?



