您的位置:首页 > 其它

flex在线展示word,excel,pdf解决方案

2014-02-27 09:52 435 查看
首先声明后台使用的是c#,

使用了四个工具第一个pdf2swf,

第二个和第三个都是dll,Aspose.Cells和Aspose.Words

第四个是flex使用的工具flexpaper

这些东西在网上都能下载到

word展示的具体思路是用Aspose.Words将word转为pdf,再把pdf转为swf,传给前台展示。

excel,和pdf思路也是一样的这里就不多说了

后台pdf转swf代码

    /// <summary>

        /// 将PDF转换为SWF文件

        /// </summary>

        /// <param name="pdfPath">PDF文件路径</param>

        /// <param name="swfPath">SWF文件路径</param>

        /// <param name="page"></param>

        private void ConvertToSwf(string pdfPath, string swfPath)

        {

            try

            {

              

                string exe = ConfigurationManager.AppSettings["ExePath"];//应用程序地址

                if (!File.Exists(exe))

                {

                    throw new ApplicationException("Can not find: " + exe);

                }

                StringBuilder sb = new StringBuilder();

                sb.Append(" -o \"" + swfPath + "\"");//output

                sb.Append(" -z");

                sb.Append(" -s flashversion=9");//flash version

                sb.Append(" -s disablelinks");//禁止PDF里面的链接

             //   sb.Append(" -p " + "1" + "-" + page);//page range

                sb.Append(" -j 100");//Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)

                sb.Append(" \"" + pdfPath + "\"");//input

                System.Diagnostics.Process proc = new System.Diagnostics.Process();

                proc.StartInfo.FileName = exe;

                proc.StartInfo.Arguments = sb.ToString();

                proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

                proc.Start();

                proc.WaitForExit();

                proc.Close();

            }

            catch (Exception ex)

            {

                throw ex;

            }

        }


后台word转pdf关键代码

    Document doc = new Document(ReturnPath+name);

    doc.Save(TemPath+name, Aspose.Words.SaveFormat.Pdf);

后台excel转pdf关键代码

    Workbook wb = new Workbook(ReturnPath + name);

    wb.Save(TemPath + name, Aspose.Cells.SaveFormat.Pdf);

前台展示代码也很简单

    <flexpaper:FlexPaperViewer id="File_ViewflexPaper" width="100%" height="100%"  SwfFile="返回的uri" / >这样后台就能直接解析了。

顺便说一下Aspose.Cells和Aspose.Words这两个功能真的很强大,我用过Aspose.Words以前处理excel用的都是NPOI下次可以试一下Aspose.Cells
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  flex word excel pdf swf