本帖最后由 liuqinglei6666 于 2009-09-25 15:49:24 编辑

解决方案 »

  1.   

    下断点 看看你传的参数filename 是什么
      

  2.   

    我调试了几次,确实是取得了一个完整的文件名,就是也能得到如:d:\\我的文档\\test.pdf这样的filename
      

  3.   

    我下载了一个测试了一下。好像没有问题啊。
    我的代码,在你的基础上作了小修改。就是在文件名两边加上"",防止路径中有空格。
    但是你测试的路径没有空格,因此应该不是这个原因。public partial class Form1 : Form
        {
            public OpenFileDialog ofdlg = new OpenFileDialog();//打开文件对话框
            public string filename;
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                ofdlg.Filter = "pdf文件(*.pdf)|*.pdf";//选择pdf文件
                if (ofdlg.ShowDialog() == DialogResult.OK)
                {
                    filename = string.Format("{0}", ofdlg.FileName);
                }        
            }        private void button2_Click(object sender, EventArgs e)
            {
                Process p = new Process();
                string path = "pdftotext.exe"; //进程启用外部程序
                //这个exe我放在debug文件夹下面        
                p.StartInfo.FileName = path;
                p.StartInfo.Arguments = string.Format("\"" + filename +"\"" + " -");//很怪异的一行
                //参数“-”表示可以得到输出流
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;            p.Start();
                string s = p.StandardOutput.ReadToEnd();//得到pdf文档中的文本内容
                textBox1.Text = s;
                p.Close();        }
        }
      

  4.   

    呵呵,谢谢楼上的兄台,下载的xpdf中xpdftotext.exe用到的配置文件xpdfrc需要手动配置,我如果把那些字体啊,什么的映射成绝对路径下的文件,就不会出现上面的问题,但是我把配置文件中的路径改成了相对路径,于是就出现了上面的问题了,看兄台能够很轻易的就运行成功,一定是做过很多代码的,这里还得劳烦兄台再给看一下,帮下忙,能遇到一个大神不容易,大神可不能吝啬啊,先谢过了哈