<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UdPdf.aspx.cs" Inherits="UdPdfWeb.UdPdf" %>

<html>
<head id="Head1" runat="server">
    <title>优道PDF阅读控件在线演示</title>    
    <style type="text/css">
        body{font-size:9pt}
        input{font-size:9pt}
        h2{background-color:#efefef;height:40px;line-height:40px;margin:0;}
        #info{background-color:#efefef;height:30px;line-height:30px;}
        .inst{display:block;border:1px solid #3079ED;background-color:#498AF4;color:#ffffff;width:300px;line-height:40px;font-weight:bold; text-decoration:none;}
        .inst:hover{background-color:#3B80EE}
        @media print 
        {
            #pdfCtl{display:none} 
            #pdfPlugin{display:none} 
            #ctlDiv{border:1px solid #000000;}
        } 
    </style>
    <script type="text/javascript" event="OnDownload(totalSize,loadingSize)" for="pdfCtl">  
	    f_onDownload(totalSize,loadingSize)
    </script>
    <script type="text/javascript" event="OnReady()" for="pdfCtl">  
	    f_onReady();        
    </script>
    <script type="text/javascript" event="OnPageChanged(currentPage,totalPage)" for="pdfCtl">  
	    f_onPageChanged(currentPage,totalPage);        
    </script>
    <script type="text/javascript" event="OnZoom(zoom)" for="pdfCtl">  
	    f_onZoom(zoom);
    </script>
    <script type="text/javascript" event="OnError(errorCode)" for="pdfCtl">  
        f_onError(errorCode);
    </script>
    <script type="text/javascript">
        //事件处理
        function f_onReady() {
            document.getElementById("info").innerHTML = "OnReady事件，文档加载完成"
            //显示书签
            if (ctl.HasBookmark) {
                document.getElementById("chkBookmark").checked = true;
                document.getElementById("chkBookmark").disabled = false;
            }
            else {
                document.getElementById("chkBookmark").disabled = true;
            }
            document.getElementById("pageInfo").value = ctl.CurrentPage + "/" + ctl.TotalPage
        }
        function f_onDownload(totalSize, loadingSize) {
            document.getElementById("info").innerHTML = "OnDownload事件，文件大小：" + totalSize + ",已加载大小:" + loadingSize
        }
        function f_onPageChanged(currentPage, totalPage) {
            document.getElementById("pageInfo").value = currentPage + "/" + totalPage;
        }
        function f_onZoom(zoom) {
            document.getElementById("info").innerHTML = "OnZoom事件，缩放比例：" + zoom + "%";
        }
        function f_onError(errorCode) {
            document.getElementById("info").innerHTML = "OnError事件，异常代号：" + errorCode
        }
    </script>
    <script type="text/javascript">
        var ctl;
        //初始化加载
        function f_onload() {
            if(window.ActiveXObject)//IE
            {
                var axobj = null;
                try{
                    axobj = new ActiveXObject('UdPdf.Viewer'); 
                }catch(e){}
                if(axobj) {
                    ctl = document.getElementById("pdfCtl");
                }
                else{
                    document.getElementById("ctlDiv").innerHTML = "<a href='UdPdf/axUdPdf.exe' class='inst'>您尚未安装PDF控件，点这里进行安装...</a>";
                }
                
            }
            else
            {
                //NOT IE
                if (navigator.plugins && navigator.plugins.length > 0)
                {
                    var plugin = navigator.plugins["UdPdf Plugin"];
                    if(plugin)
                        ctl = document.getElementById("pdfPlugin");
                    else
                        document.getElementById("ctlDiv").innerHTML = "<a href='UdPdf/npUdPdf.exe' target='_blank' class='inst'>您尚未安装PDF插件，点这里进行安装...</a>";
                }        
                else
                    document.getElementById("ctlDiv").innerHTML = "<span class='inst'>当前浏览器不支持插件<span>";        
            }
            <%if(!string.IsNullOrEmpty(Request.QueryString["file"])){ %>
            if(ctl)
            {                
                ctl.Encrypted = 1; //采用加密方式加载
                ctl.HashKey = "3CE59E850E2C590AFD6E4D3516BA3F1B";//使用加密读取的密码hash值：123abc
                ctl.FileId = "<%=Server.UrlDecode(Request.QueryString["file"]) %>";   //更改文件ID值
                ctl.LoadFromWeb("");
            }
            <%} %>
        }
        //通过路径打开文件
        function f_open(){  
            //设为非加密模式读取
            ctl.Encrypted = 0;           

            //打开其它网站文件，http开头的为绝对路径
            //ctl.LoadFromWeb("http://www.jslanfeng.com/download/upfile/2012020639708721.PDF"); 

            //相对路径打开当前服务器文件
            //ctl.LoadFromWeb("upload/sample.pdf"); 

            //也可通过URL读取文件
            ctl.FileId = "sample"
            ctl.LoadFromWeb("GetFile.aspx","","post");//POST方式请求
        }
        //放大
        function f_zoomIn() {
            ctl.ZoomIn();
        }
        //缩小
        function f_zoomOut() {
            ctl.ZoomOut();
        }
        //获取缩放比例
        function f_getZoom()
        {
            alert("当前缩放比例：" + ctl.GetZoom());
        }
        //适应宽度
        function f_zoomFitWidth() {
            ctl.ZoomFitWidth();
        }
        //适应页面
        function f_zoomFitPage() {
            ctl.ZoomFitPage();
        }
        //原始大小
        function f_zoomActual() {
            ctl.ZoomActual();
        }
        //顺时针旋转
        function f_rotateLeft() {
            ctl.RotateLeft();
        }
        //逆时针旋转
        function f_rotateRight() {
            ctl.RotateRight();
        }
        //上页
        function f_gotoPrevPage() {
            ctl.GoToPrevPage();
        }
        //下页
        function f_gotoNextPage() {
            ctl.GoToNextPage();
        }
        //允许打印
        function f_enablePrint() {
            //ctl.EnablePrint = document.getElementById("chkEnablePrint").checked
            //也可以用加密方式设置
            if(document.getElementById("chkEnablePrint").checked)
		        ctl.EncryptExecute("22286F074E914C269FE84EB6FD1473771CD9FD9AAAD7141A9CCE9A3DC567036CF99E3DD7B52282441B6A3FCC6E9BA168")//EnablePrint=true
	        else
		        ctl.EncryptExecute("22286F074E914C269FE84EB6FD1473771A35B23CCF238ECD7999BCD7885726B552F3EA272B29E87023868FB7D5F7A69C")//EnablePrint=false
        }
        //允许复制
        function f_enableCopy() {
            //ctl.EnableCopy = document.getElementById("chkEnableCopy").checked
            //也可以用加密方式设置
            if(document.getElementById("chkEnableCopy").checked)
		        ctl.EncryptExecute("74321C08CA9D4B127A06C1B07A78A8B11E2CB74C64AE25C4D42847F22A5F7B04")//EnableCopy=true
	        else
		        ctl.EncryptExecute("74321C08CA9D4B127A06C1B07A78A8B1344B4A88E7F2517D90A04FFEB46F7A9FF99E3DD7B52282441B6A3FCC6E9BA168")//EnableCopy=false
        }
        //允许截图
        function f_enableCapture() {
            ctl.EnableCapture = document.getElementById("chkEnableCapture").checked
        }
        //显示工具条
        function f_toolbarVisible() {
            ctl.ToolbarVisible = document.getElementById("chkToolbarVisible").checked
        }
        //打印
        function f_print() {
            ctl.Print();
        }
        //获取页码信息
        function f_getpage(){
            alert("共" + ctl.TotalPage + "页,第" + ctl.CurrentPage + "页");
        }
        //显示书签页
        function f_showBookmark()
        {
            ctl.BookmarkVisible = document.getElementById("chkBookmark").checked
        }
        //向下查找
        function f_findNext() {
            ctl.FindNext(document.getElementById("findText").value);
        }
        //向上查找
        function f_findPrev(text) {
            ctl.FindPrev(document.getElementById("findText").value)
        }
        //全屏显示
	    function f_fullScreen(){
	        ctl.ToggleFullScreen()
	    }
        //关闭文档
        function f_close(){
            ctl.Close();
        }
        //动态水印演示
        var water1 = -1, water2 = -1
        function f_waterMark() {
            if (water1 > -1) {
                ctl.RemoveWaterMark(water1)
                water1 = -1;
            }
            else {
                ctl.SetWaterFont("宋体", 20, 100, 1);
                water1 = ctl.AddWaterText("这里是动态添加的水印", 20, 100);
            }

            if (water2 > -1) {
                ctl.RemoveWaterMark(water2);
                water2 = -1;
            }
            else {
                ctl.SetWaterFont("宋体", 40, 300);
                water2 = ctl.AddWaterText("斜体的水印文字", 100, 300, 50, 45);
            }
        }
    </script>
</head>
<body onload="f_onload()">
    <form id="form1" runat="server">
    <center>
    <h2>优道PDF阅读控件在线演示</h2>
    <div style="height:20px;clear:both"></div>
    <div style="height:600px" id="ctlDiv">
        <object id="pdfCtl" width="100%" height="600" classid="CLSID:8C3D3705-1100-4D52-9D04-7E9A435CE220" codebase="UdPdf/axUdPdf.exe#Version=2,0,0,0">
         <param name="License" value="" />

         <embed id="pdfPlugin" width="100%" height="600" type="application/udpdf-plugin" pluginspage="UdPdf/npUdPdf.exe#Version=2,0,0,0"
            License=""
            onReady="f_onReady" onDownload="f_onDownload" onPageChanged="f_onPageChanged" onZoom="f_onZoom" onError="f_onError"></embed>
        </object>
    </div>
    <div>
        <p>
            <input type="button" id="btnOpen" value="打开文件" onclick="f_open()" />
            <input type="button" id="btnZoomIn" value="放大" onclick="f_zoomIn()" />
            <input type="button" id="btnZoomOut" value="缩小" onclick="f_zoomOut()" />   
            <input type="button" id="btnGetZoom" value="缩放比例" onclick="f_getZoom()" />      
            <input type="button" id="btnZoomFitWidth" value="适应宽度" onclick="f_zoomFitWidth()" />
            <input type="button" id="btnZoomFitPage" value="适应页面" onclick="f_zoomFitPage()" />
            <input type="button" id="btnZoomActual" value="实际大小" onclick="f_zoomActual()" />
            <input type="button" id="btnClockwise" value="顺时针旋转90度" onclick="f_rotateLeft()"/>
            <input type="button" id="btnContrarotate" value="逆时针旋转90度" onclick="f_rotateRight()" />
            <input type="button" id="btnGotoNextPage" value="下页" onclick="f_gotoNextPage()" />
            <input type="button" id="btnGotoPrevPage" value="上页" onclick="f_gotoPrevPage()" />
            <input type="button" id="btnPrint" value="打印" onclick="f_print()" />
            页码：<input type="text" id="pageInfo" style="width:60px" readonly="readonly" />
            <input type="button" id="btnGetPage" value="获取页码" onclick="f_getpage()" />
        </p>
        <p>
            <input type="checkbox" id="chkToolbarVisible" value="1" onclick="f_toolbarVisible()" checked="checked" /><label for="chkToolbarVisible">显示工具条</label>
            <input type="checkbox" id="chkEnableCapture" value="1" onclick="f_enableCapture()" checked="checked"  /><label for="chkEnableCapture">允许截图</label>
            <input type="checkbox" id="chkEnablePrint" value="1" onclick="f_enablePrint()" checked="checked" /><label for="chkEnablePrint">允许打印</label>
            <input type="checkbox" id="chkEnableCopy" value="1" onclick="f_enableCopy()"  checked="checked" /><label for="chkEnableCopy">允许内容复制</label>
            <input type="checkbox" id="chkWaterMark" value="1" onclick="f_waterMark()" /><label for="chkWaterMark">动态水印</label>
            <input type="checkbox" id="chkBookmark" value="1" onclick="f_showBookmark()"  checked="checked" disabled="disabled" /><label for="chkBookmark">显示书签</label>
            <input type="text" id="findText" />
            <input type="button" id="btnFindNext" value="向下查找" onclick="f_findNext()"/>
            <input type="button" id="btnFindPrev" value="向上查找" onclick="f_findPrev()"/>            
            <input type="button" id="btnFullScreen" value="全屏显示" onclick="f_fullScreen()" />
            <input type="button" id="btnClose" value="关闭" onclick="f_close()" />
        </p>
    </div>
    <div id="info"></div>
        <p><a href="http://www.uudoc.com">www.uudoc.com</a></p>
    </center>
    </form>
</body>
</html>
