Tag:开源 , 源码 , 控件 , 控件开发 , 皮肤 , Skin , Web Service , AJAX , JQuery , Flex , Silverlight , Javascript , CSS , SQL , 网站开发 , 数据库 , 用户自定义PDF浏览控件(无需Acrobat Reader安装)
 CS Windows 程序员之窗
 
您的位置: >> 首页 >> .Net视角 >> 用户自定义PDF浏览控件(无需Acrobat Reader安装)

用户自定义PDF浏览控件(无需Acrobat Reader安装)

2010-02-04  来自:csharpwin.com  字体大小:【  
  • 摘要:本文推荐一个ASP.NET用户自定义PDF浏览阅读控件,使用该控件无需客户端安装Acrobat Reader
使用流程:
1、下载附件后,将web.config和default.aspx删除;
2、将附件中的Web项目进行生成发布;
3、建立自己的应用Web项目;
4、之后:
(1)将附件Web项目发布文件夹中的images,PDF,render,lib,PDFViewer.ascx拷贝到新建的web项目文件夹中;

(2)将附件Web项目发布文件夹中bin目录下生成的PDFLibNet.dll,PDFViewASP.dll,StatefullScrollPanel.dll文件拷贝
到新建的web项目文件夹的bin目录中;

新建Web项目的解决方案如下图所示:

(3)在新建Web项目中将PDFViewer.ascx直接拖到需要使用该控件的页面,并在该页面中放一个FileUpload、一个Button、一个Label


前台页面代码:
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" Width="224px" />
<asp:Button ID="Button1" runat="server" Text="View PDF"
onclick
="Button1_Click" />
&nbsp;&nbsp;<asp:Label ID="ErrorLabel" runat="server" Text="" ForeColor="#CC0000" Visible="False"></asp:Label>

</div>
<uc1:PDFViewer ID="PDFViewer1" runat="server" />
</form>

后台CS代码:
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
if(this.FileUpload1.HasFile)
{
if(PDFViewASP.ImageUtil.IsPDF(this.FileUpload1.FileName))
{
this.ErrorLabel.Visible=false;
string savePath=Request.MapPath("PDF")+@"\"+this.FileUpload1.FileName;
this.FileUpload1.SaveAs(savePath);
PDFViewer1.FileName
= savePath;
}
else
{
this.ErrorLabel.Text="Only PDF files (*.pdf) are allowed to be uploaded.";
this.ErrorLabel.Visible=true;
}
}

}
}

后台VB代码:
Partial Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub

'Current Upload limit is 25 MB (25000 k)
'Change maxRequestLength in Web.config to set the upload limit

'Current Upload timeout is 5 minutes (300 seconds)
'Change executionTimeout in Web.config to set the upload timeout

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
If FileUpload1.HasFile Then
If PDFViewASP.ImageUtil.IsPDF(FileUpload1.FileName) Then
ErrorLabel.Visible
= False
Dim savePath As String = Request.MapPath("PDF") & "\" & FileUpload1.FileName
FileUpload1.SaveAs(savePath)
PDFViewer1.FileName
= savePath
Else
ErrorLabel.Text
= "Only PDF files (*.pdf) are allowed to be uploaded."
ErrorLabel.Visible
= True
End If
End If
End Sub

End Class
作者:黑浪

相关文章:
Website Statisticsflip hd camcorder