Pergunta

I have a project need use pdf2swf to convert pdf to swf. I use swftool 0.9.1 for windows. File pdf2swf.exe is in upload folder. I want convert automatically. I use it on Asp.net development sever. I use this code:

protected void Page_Load(object sender, EventArgs e)
{
    System.Diagnostics.Process p = new System.Diagnostics.Process();

    p.StartInfo.UseShellExecute = false;

    p.StartInfo.RedirectStandardOutput = true;

    p.StartInfo.CreateNoWindow = true;

    p.StartInfo.RedirectStandardError = true;

    p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~");

    p.StartInfo.FileName = HttpContext.Current.Server.MapPath("~/upload/pdf2swf.exe");

    p.StartInfo.Arguments = " -b " + "alo.pdf" + " -o " + "alo" + ".swf";

    //Start the process

    p.Start();
    TextBox1.Text = p.StandardOutput.ReadToEnd();
    TextBox2.Text = p.StandardError.ReadToEnd();
    p.WaitForExit();
    p.Close();
}

When I view this page in browser, this page displays normaly, no error. But the most importal thing is file .swf not create. Please help me how to fix it! Thanks for your help! I tried to run pdf2swf from a web application. When I view in browser this page the String error output is: Error: Couldn't open file 'alo.pdf'. But it is existed.

Foi útil?

Solução

Ensure that p.StartInfo.WorkingDirectory points to a directory where pdf files are located. If those files are in upload directory, than it should be:

 p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/upload");

This property specifies a working directory (default directory where files will be searched by pdf2swf, if no path specified) for pdf2swf. Currently it will search for PDF files in HttpContext.Current.Server.MapPath("~") directory.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top