隐藏

C#代码使用Process类调用SWFTools工具

发布:2020/2/18 11:44:31作者:管理员 来源:本站 浏览次数:1076

一。Process类调用SWFTools工具将PDF文档转为swf文档
 string cmdStr = "D:\\SWFTools\\pdf2swf.exe";
 string PDFPath = HttpContext.Current.Server.MapPath("PDFFile/liuzeliang.pdf");
 string SWFPath = HttpContext.Current.Server.MapPath("SWFFile");
 string args = " -o "+"\""+SWFPath+"\\liuzeliang.swf"+"\""+ " -s flashversion=9 " + "\""+ PDFPath+"\"";

using (Process p = new Process())
            {
                try
                {
                    p.StartInfo.FileName = cmdStr;
                    p.StartInfo.Arguments = args;
                    p.StartInfo.UseShellExecute = false;         //不使用系统外壳程序启动
                    p.StartInfo.RedirectStandardInput = true;
                    p.StartInfo.CreateNoWindow = false;
                    p.Start();
                    //p.StandardInput.WriteLine(args);
                    p.WaitForExit();
                    if (p != null)
                    {
                        p.Close();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }

遇到的问题大概如下(swftools-0.9.0  Windows版本 官网下载地址:http://www.swftools.org/download.html):
    1.调用pdf2swf.exe将pdf转swf失败。
原因:swf文件存放路径含义空格(红色部分D:\Users\zeliang.liu\Documents\Visual Studio 2015\Projects\FlexPaperTest\FlexPaperTest\SWFFile)
          解决方法:给整个路径用双引号括起来。(红色部分:string args = " -o "+"\""+SWFPath+"\\liuzeliang.swf"+"\""+ " -s flashversion=9 " + "\""+ PDFPath+"\"";)               
    2.转换成功后调用FlexPaper无法显示。
原因:swf文件版本问题。
解决方法:在传入process的参数里加入 -s flashversion=9 注意=前后不要有空格。(其实我刚开始用的-T并不能成功显示)

二。利用flexpaper插件显示swf文件


1.先下载好flexpaper的.rar包,然后将包中的js复制到项目中在引用下面俩个js到页面(我的flexpaper是1.4.5版本的)

2.将文件夹中的FlexPaperViewer.swf放到项目中去

<script src="scripts/flexpaper/jquery.js"></script>
<script src="scripts/flexpaper/flexpaper_flash.js"></script>
<a id="viewerPlaceHolder" style="width:660px;height:480px;display:block"></a>
                 <script type="text/javascript">
                     var swfFile = "SWFFile/liuzeliang.swf";
                     var fp = new FlexPaperViewer(
                                                         ///FlexPaper组件的SWF框架路径
                                                         'scripts/flexpaper/FlexPaperViewer',
                                                         'viewerPlaceHolder',
                                                         {
                                                            config:
                                                            {
                                                             ///需要显示的.swf
                                                             SwfFile: escape(swfFile),
                                                             Scale: 0.6,
                                                             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: 'en_US'
                                                         }
                                                         });
 

                 </script>




Windows Version (Binaries):

Size Date Name  
14122496 2009-07-21 swftools-0.9.0.exe  
2966528 2007-02-28 swftools-0.8.1.exe  
3102208 2007-01-21 swftools-0.8.0.exe  
3976192 2005-08-06 swftools-0.7.0.exe  
3842048 2005-02-06 swftools-0.6.3.exe  
3602199 2004-10-08 swftools-0.6.2.exe  
3303703 2004-08-20 swftools-0.6.1.exe  

GIT

git clone git://github.com/matthiaskramm/swftools