日期:2014-05-18  浏览次数:20818 次

asp.net调用FlashPaper讲PDF转换成SWF

  string root = Server.MapPath("~/"); // 获取虚拟路径。
  string path = this.FileUpload1.PostedFile.FileName; // 获取上传文件的路径。
  string name = System.IO.Path.GetFileName(path); // 获取上传文件的名称,包括后缀。
  string outPath = string.Format("{0}{1}{2}", root, "allFiles\\", name); // 合并上传文件的保存路径。
  string swfPath = string.Format("{0}{1}{2}.swf", root, "swfFiles\\", Guid.NewGuid().ToString("N")); // 合并Swf文件保存的路径。
  this.FileUpload1.PostedFile.SaveAs(outPath); // 保存上传的文件到指定的路径。
  // 通过注册表获取FlashPrinter.exe注册的路径。注:/初始化/初始化.bat 一定要执行过此文件后才可以获取路径。
  string appPath = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\FlashPaper Printer\2\Installation", "AppPath", null);
  string param = string.Format("{0} -o {1}", outPath, swfPath); // 合并需要的参数信息。
  this.FileUpload1.PostedFile.SaveAs(swfPath);  
  // 创建一个进程。
  System.Diagnostics.Process p = new System.Diagnostics.Process();
  p.StartInfo.FileName = appPath; // 赋值进程要执行的应用程序。
  p.StartInfo.Arguments = param; // 赋值应用程序可用参数。
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.RedirectStandardInput = false;
  p.StartInfo.RedirectStandardOutput = false;
  p.StartInfo.RedirectStandardError = false;
  p.StartInfo.CreateNoWindow = true; // 是否创建显示窗口。
  try
  {
  bool IsStart = p.Start(); // 开始执行程序,如果执行成功返回True,否则False。
  p.WaitForExit(); // 等待关联进程退出。
  p.Close(); // 关闭进程。
  }
  catch(Exception ex)
  {
  throw ex;
  }
  Response.Write("完成。");  
  }



不知道哪个地方出了问题。

------解决方案--------------------
Process process = new Process(); //创建进程对象 
//try 
//{ 
ProcessStartInfo startInfo = new ProcessStartInfo();
string paperroot = @"F:\FlashPaper2.2\FlashPrinter.exe";
string docFile = Server.MapPath("Files/asdf.xls");
string swfFile = Server.MapPath("Files/asdf.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();