1. 程式人生 > >flexpaper在.net中的應用

flexpaper在.net中的應用

前提準備 flexpaper、pdf2swf可在我的部落格資源中下載。
下面貼出處理的相關程式碼
起始頁:

 <div style="text-align: center;">
            <label>檔案上傳</label>
            <asp:FileUpload ID="UploadFile" runat="server" />
            <asp:Button ID="btnUp" runat="server" OnClick="btnUp_Click" Text="檔案上傳"
/> <label>PDF上傳的檔案:</label> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="檢視" /> </div> //後端程式碼 /// <summary> /// 檔案上傳 /// </summary> /// <param name="sender"></param> /// <param name="e">
</param>
protected void btnUp_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.UploadFile.FileName)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "32uewqhiuewd", "<script type=\"text/javascript\">alert(\"請選擇檔案進行上傳!\")</script>"
); return; } string Extension = Path.GetExtension(this.UploadFile.FileName); if (Extension.ToLower() != ".pdf") { Page.ClientScript.RegisterStartupScript(this.GetType(), "32uewqhiuewd", "<script type=\"text/javascript\">alert(\"請上傳pdf格式的檔案!\")</script>"); return; } string filePath = Server.MapPath("~/uploads/"); if (!Directory.Exists(filePath)) Directory.CreateDirectory(filePath); this.UploadFile.SaveAs(filePath + this.UploadFile.FileName); imgSrc.Src = filePath + "06_button_5.jpeg"; string cmdStr = Server.MapPath("~/SWFTools/pdf2swf.exe"); string sourcePath = @"""" + filePath + this.UploadFile.FileName + @""""; string targetPath = @"""" + (filePath + this.UploadFile.FileName).Substring(0, (filePath + this.UploadFile.FileName).Length - 4) + ".swf" + @""""; string argsStr = " -t " + sourcePath + " -s flashversion=9 -o " + targetPath; using (Process p = new Process()) { ProcessStartInfo psi = new ProcessStartInfo(cmdStr,argsStr); p.StartInfo = psi; p.Start(); p.WaitForExit(); } } /// <summary> /// swf檢視 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/uploads/")); if (dir.GetFiles("*.swf").Length > 0)//檢測是否存在.swf檔案 { string fileName= string.Empty; foreach (FileInfo fi in dir.GetFiles("*.swf")) { fileName = fi.Name; break; } Response.Redirect("SWFTools/SWFViewer.aspx?FilePath=../uploads/" + fileName + ""); } }

點選檢視後:展示資訊頁面

<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../FlexPaper/js/jquery.js"></script>
    <script src="../FlexPaper/js/flexpaper_flash_debug.js"></script>
    <script src="../FlexPaper/js/flexpaper_flash.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div style="margin: 0 auto; width: 98%; text-align: center;">
            <div style="position: absolute; left: 15%; top: 20px; height: 98%;">
                <a id="viewerPlaceHolder" style="width: 1000px; height: 95%; display: block;"></a>
                <!--設定一個隱蔽控制元件來得到要顯示的檔案的名字-->
                <input type="hidden" id="file" runat="server" />
                <script type="text/javascript">
                    var fileURL = $("#file").val();
                    var fp = new FlexPaperViewer(
                '../FlexPaper/FlexPaperViewer',
                'viewerPlaceHolder',
                {
                    config: {
                        SwfFile: escape(fileURL),
                        Scale: 1.2,
                        ZoomTransition: 'easeOut',
                        ZoomTime: 0.5,
                        ZoomInterval: 0.2,
                        FitPageOnLoad: false,
                        FitWidthOnLoad: false,
                        PrintEnabled: true,
                        FullScreenAsMaxWindow: false,
                        ProgressiveLoading: false,
                        MinZoomSize: 0.2,
                        MaxZoomSize: 5,
                        SearchMatchAll: false,
                        InitViewMode: 'Portrait',
                        ViewModeToolsVisible: true,
                        ZoomToolsVisible: true,
                        NavToolsVisible: true,
                        CursorToolsVisible: true,
                        SearchToolsVisible: true,
                        localeChain: 'zh_CN'
                    }
                }
                );
                </script>
            </div>
        </div>
    </form>
</body>
後端處理:
 protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["FilePath"] != null)
            {
                this.file.Value = Request.QueryString["FilePath"].ToString().Replace("\\","/");
            }
        }

也可在我的資源中下載原始碼檢視 開發工具 vs2012
圖片案例:
這裡寫圖片描述