PDF在线编辑器的实现
2012-02-02 15:01
127 查看
1、新建类库PdfViewer,在类库中建立一个ShowPdf的类,代码如下:
2、在WEB项目中添加引用类库PdfViewer,以下是页面代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace PdfViewer { [DefaultProperty("FilePath")] [ToolboxData("<{0}:ShowPdf runat=server></{0}:ShowPdf>")] public class ShowPdf : WebControl { #region "Declarations" private string mFilePath; #endregion #region "Properties" [Category("Source File")] [Browsable(true)] [Description("Set path to source file.")] [Editor(typeof(System.Web.UI.Design.UrlEditor), typeof(System.Drawing.Design.UITypeEditor))] public string FilePath { get { return mFilePath; } set { if (value == string.Empty) { mFilePath = string.Empty; } else { int tilde = -1; tilde = value.IndexOf('~'); if (tilde != -1) { mFilePath = value.Substring((tilde + 2)).Trim(); } else { mFilePath = value; } } } } // end FilePath property #endregion #region "Rendering" protected override void RenderContents(HtmlTextWriter writer) { try { StringBuilder sb = new StringBuilder(); sb.Append("<iframe src=" + FilePath.ToString() + " "); sb.Append("width=" + Width.ToString() + " height=" + Height.ToString() + " "); sb.Append("<View PDF: <a href=" + FilePath.ToString() + "</a></p> "); sb.Append("</iframe>"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.Write(sb.ToString()); writer.RenderEndTag(); } catch { // with no properties set, this will render "Display PDF Control" in a // a box on the page writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.Write("Display PDF Control"); writer.RenderEndTag(); } // end try-catch } // end RenderContents #endregion } // end class } // end namespace
2、在WEB项目中添加引用类库PdfViewer,以下是页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PdfTestSite._Default" %> <%@ Register Assembly="PdfViewer" Namespace="PdfViewer" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>PDF文档在线编辑测试</title> </head> <body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" style="font-family: Calibri" bgcolor="#cccccc"> <form id="form1" runat="server"> <div> <asp:Panel ID="Panel1" runat="server" BackColor="LightSlateGray" BorderStyle="Outset" BorderWidth="2px" Font-Bold="True" Font-Names="Calibri" Font-Size="X-Large" ForeColor="White" Height="80px" Style="z-index: 100; left: 0px; position: absolute; top: 0px" Width="100%"> <br /> PDF在线编辑<br /> </asp:Panel> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/ABC.pdf" Style="z-index: 101; left: 24px; position: absolute; top: 96px">在新窗口打开PDF文档</asp:HyperLink> <cc1:ShowPdf ID="ShowPdf1" runat="server" BorderStyle="Inset" BorderWidth="2px" FilePath="ABC.pdf" Height="352px" Style="z-index: 103; left: 24px; position: absolute; top: 128px" Width="856px" /> </div> </form> </body> </html>
相关文章推荐
- 实现在线阅读WORD,PDF等文件,JAVA,PHP都可以
- SSH2 struts2 在线编辑器实现
- 调用office web 365接口实现在线预览word文档,PDF,PPT
- 8个实现在线浏览PDF文件的实用jQuery插件
- 一个文章在线编辑器的实现
- 在线编辑器的基本实现原理
- 利用FlexPaper实现Word、PPT、PDF在线浏览
- asp.net实现word、excel、ppt、pdf在线预览
- SSH2 struts2 在线编辑器实现
- Office在线预览及PDF在线预览的实现方式大集合
- ASP.NET一款免费富文本(RichText)编辑器KindEditor,实现在线排版编辑文章。这里简单介绍下如何使用
- C# web实现word 转Html、office转Html、pdf转图片 在线预览文件
- 在线编辑器的实现原理(兼容IE和FireFox)
- 基于web的在线复杂公式编辑器的实现
- Jquery UI实战: Draggable and Resizable 实现pdf在线批注
- WebRTC与Ace在线代码编辑器合作,实现实时协作编程
- Android实现在线预览office文档(Word,Pdf,excel,PPT.txt等格式)
- 跨浏览器仿模式对话框的实现-集成方式最简单的在线Web编辑器(5分钟内完成集成)
- SSH2 struts2 在线编辑器实现
- 网页实现pdf在线阅读------纯属自己测试总结