.NET实现在网页中预览Office文件的3个方法(4)_.Net教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:asp.net中控制反转怎么理解?
对IOC的解释为:Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels. 我想对这一概念执行

        #region 2.02 转换PDF文件为SWF格式 +PDFConvertToSwf(string pdfPath, string swfPath, int page)
        /// <summary>
        /// 转换PDF文件为SWF格式
        /// </summary>
        /// <param name="pdfPath">PDF文件路径</param>
        /// <param name="swfPath">SWF生成目标文件路径</param>
        /// <param name="page">PDF页数</param>
        /// <returns>生成是否成功</returns>
        public static bool PDFConvertToSwf(string pdfPath, string swfPath, int page)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" \"" + pdfPath + "\"");
            sb.Append(" -o \"" + swfPath + "\"");
            sb.Append(" -z");
            //flash version
            sb.Append(" -s flashversion=9");
            //禁止PDF里面的链接
            sb.Append(" -s disablelinks");
            //PDF页数
            sb.Append(" -p " + "\"1" + "-" + page + "\"");
            //SWF中的图片质量
            sb.Append(" -j 100");
            string command = sb.ToString();
            System.Diagnostics.Process p = null;
            try
            {
                using (p = new System.Diagnostics.Process())
                {
                    p.StartInfo.FileName = _EXEFILENAME;
                    p.StartInfo.Arguments = command;
                    p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(_EXEFILENAME);
                    //不使用操作系统外壳程序 启动 线程
                    p.StartInfo.UseShellExecute = false;
                    //p.StartInfo.RedirectStandardInput = true;
                    //p.StartInfo.RedirectStandardOutput = true;

                    //把外部程序错误输出写到StandardError流中(pdf2swf.exe的所有输出信息,都为错误输出流,用 StandardOutput是捕获不到任何消息的...
                    p.StartInfo.RedirectStandardError = true;
                    //不创建进程窗口
                    p.StartInfo.CreateNoWindow = false;
                    //启动进程
                    p.Start();
                    //开始异步读取
                    p.BeginErrorReadLine();
                    //等待完成
                    p.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                Souxuexiao.API.Logger.error(string.Format("转换PDF文件为SWF格式执行PDFConvertToSwf函数发生异常原因是:{0}", ex.Message));
            }
            finally
            {
                if (p != null)
                {
                    //关闭进程
                    p.Close();
                    //释放资源
                    p.Dispose();
                }
            }
            return File.Exists(swfPath);
        }
        #endregion
    }
}
Office格式转换

 

3、将pdf文件转swf的转换器放到站点根目录下新建文件夹pdf2swf(我就是这么配置的,您随意)

4、配置FlexPaper

预览页面引用

分享:delphi选择文件夹例子
所需单元 示例代码

来源:模板无忧//所属分类:.Net教程/更新时间:2014-10-11
相关.Net教程