.net实现百度文库功能

关联工具及关联软件


flashprinter驱动程序(转成swf文件就要靠他了)


FlashPaper2.02绿色版


安装过程中:360会报警告,允许操作即可




swftools-0.9.1

PDF/JPEG/PNG/AVI/TTF/WAV 到 SWF 的转换工具 :pdf2swf, jpeg2swf, png2swf, avi2swf, font2swf, and wav2swf|


Office另存为pdf或xps文件补丁包(安装后,在保存文档的时候选择另存为pdf或xps文件即可)


实现机制



环境配置

环境配置算是比较麻烦的吧

1.首先安装swftools-0.9.1  记录swftools的安装路径,在代码中要使用到


2.安装flashpaper,主要是看安装后是否能转换成功,同时flashprinter是否已安装上.在转化文档的之前,要将服务器的打印机默认成首用打印机



3.安装好以上这两个后,还要安装一下


核心代码


///
        /// 由文件名生成Flash文件名
        ///

        ///
        ///
        public static string  GetFlashName(string fileName)
        {
            int d = fileName.LastIndexOf(".");
            if (d != -1)
            {
                return fileName.Substring(0, d) + ".swf";
            }
            else
            {
                return fileName + ".swf";
            }
        }

        /////
        ///// 获取文档路径
        /////

        /////
        /////
        //public static string GetFilePath(string fileName)
        //{
        //    return System.Web.HttpContext.Current.Server.MapPath(fileName);
        //}

        public static string GetFilePath(string fileName)
        {
            return fileName;
        }
        ///
        /// 获取Flash路径
        ///

        ///
        ///
        public static string GetFlashPath(string flashFile)
        {
            //return System.Web.HttpContext.Current.Server.MapPath("~/Resource" + flashFile);

            return flashFile;
        }

      



        ///
        /// 转换文件
        ///

        ///
        ///
        public static Boolean ConvertFile(string filePath,string fileName)
        {
            //FlashPaper文件安装路径 可自行设置
            //string flashPrinter = "c:/Program Files/Macromedia/FlashPaper 2/FlashPrinter.exe";

            string flashPrinter = *****.****.WINFORM.TASK.Config.strFlashPaperPath;

          

            if (File.Exists(flashPrinter))//检查flashpaper是否存在
            {

                string inFile = GetFilePath(filePath);

                string outFile = GetFlashPath(GetFlashName(fileName));

                //进程操作
                Process pss = new Process();
                pss.StartInfo.CreateNoWindow = false;
                pss.StartInfo.FileName = flashPrinter;
                pss.StartInfo.Arguments = string.Format("{0} {1} -o {2}", flashPrinter, inFile, outFile);
                try
                {
                    pss.Start();
                    //设置300*200毫秒不结束则退出循环
                    for (int i = 0; i < 300 && !File.Exists(outFile); i += 1)

                        System.Threading.Thread.Sleep(200);//挂起2秒

                    //返回输出文件是否存在


                    return File.Exists(outFile);


                }
                catch (Exception)
                {
                    //如果报错 将输出文件删除
                    if (File.Exists(outFile)) File.Delete(outFile);
                    return false;
                }
                finally
                {
                    //如果进程还未结束,杀死进程树
                    if (!pss.HasExited) KillProcess(pss.Id);
                }
            }
            else
            
              
            
                return false;
            

        }
        
        ///
        /// 杀死进程树
        ///

        ///
        ///
        private static bool KillProcess(int pid)
        {
            Process[] procs = Process.GetProcesses();
            for (int i = 0; i < procs.Length; i++)
            {
                if (GetParentProcess(procs[i].Id) == pid)
                    KillProcess(procs[i].Id);
            }

            try
            {
                Process myProc = Process.GetProcessById(pid);
                myProc.Kill();
            }
            catch (ArgumentException)
            {
                ;
            }

            return true;
        }

        ///
        /// 获取父进程
        ///

        ///
        ///
        private static int GetParentProcess(int Id)
        {
            int parentPid = 0;
            using (ManagementObject mo = new ManagementObject("win32_process.handle='" + Id.ToString(CultureInfo.InvariantCulture) + "'"))
            {
                try
                {
                    mo.Get();
                }
                catch (ManagementException)
                {
                    return -1;
                }
                parentPid = Convert.ToInt32(mo["ParentProcessId"], CultureInfo.InvariantCulture);
            }
            return parentPid;
        }




参考文档

.Net初次使用FlashPaper
http://www.cnblogs.com/sobne/articles/1822479.html

FlexPaper实现文档在线浏览(附源码)
http://www.cnblogs.com/ke10/archive/2012/09/06/ToSwf.html

asp.net调用flashpaper实现类似百度文库的功能解决方案
http://bbs.csdn.net/topics/360221812

flashpaper使用详解
http://blog.csdn.net/dasihg/article/details/7018964



[本日志由 admin 于 2015-12-03 09:21 AM 更新]
上一篇: 挺有个性的PPT教程
下一篇: 意外
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 百度文库功能 类百度文库
相关日志:
评论: 0 | 引用: 0 | 查看次数: 4142
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 30 字 | UBB代码 关闭 | [img]标签 关闭