FlashPaper是一个虚拟打印机,可将word文件转化成swf格式文件(.doc .xls .txt .pdf等文件都可以正常生成SWF格式)。最近简单学习了在ASP.NET页面中调用FlashPaper将word文件转化成swf格式文件的方法。 (1)安装FlashPape:下载FlashPape压缩包,解压缩后,运行初始化目录中的初始化.bat,然后安装FlashPaperDriverInstall2.exe,即FlashPaper打印机。特别注意,在有的机器上要更改Macromedia FlashPape的端口,应为FlashPape2PrinterPort,如果是LPT1这个端口,当然打印不出来了。 (2)为页面中的按钮编写事件处理代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Process process = new Process(); //创建进程对象 //try //{ ProcessStartInfo startInfo = new ProcessStartInfo(); string paperroot = @"C:\Program Files\Macromedia\FlashPaper 2\FlashPrinter.exe"; string docFile = Server.MapPath("1.doc"); string swfFile = Server.MapPath("1.swf"); startInfo.FileName = paperroot; startInfo.Arguments = docFile + " -o " + swfFile; startInfo.UseShellExecute = false; //不使用系统外壳程序启动 startInfo.RedirectStandardInput = false; //不重定向输入 startInfo.RedirectStandardOutput = false; //重定向输出 startInfo.CreateNoWindow = true; //不创建窗口 process.StartInfo = startInfo; process.Start(); Response.Write("已经提交生成。<br />"); Response.Write(paperroot+"<br />"+docFile + " = " + swfFile); //} //catch (Exception ex) //{ // Response.Write(ex.Message); //} //finally //{ if (process != null) process.Close(); // Response.Write("<br />finally"); //} |
示例代码3:
1 |
public static void TransformFile(string filepath) |
{ string fppath = System.Configuration.ConfigurationManager.AppSettings["Flashpaper"]; string outpath = filepath.Substring(0, filepath.LastIndexOf('.')) + ".swf"; string param = fppath + " " + filepath + " -o " + outpath; Process p = new Process(); p.StartInfo.FileName = "C:\\WINDOWS\\system32\\cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; //p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; try { p.Start(); string strOutput = null; p.StandardInput.WriteLine(param); p.StandardInput.WriteLine("exit"); strOutput = p.StandardOutput.ReadToEnd(); Console.WriteLine(strOutput); p.WaitForExit(); p.Close(); } catch (Exception ex) { throw ex; } }
View Details