日期:2014-05-18 浏览次数:21147 次
namespace 利用xpdf提取pcf文档的txt
{
    public partial class Form1 : Form
    {   
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {          
            string path = "pdftotext.exe";//这是debug包
             //下的exe,利用它来做转化得到输出
            string filename = @"d:\我的文档\桌面\test.pdf";//这是一个pdf文件
            //得用process类启动外部程序
            Process p = new Process();
            p.StartInfo.FileName = path;
            p.StartInfo.Arguments = string.Format("-nopgbrk " + filename + " -") ;//pdftoexe执行所需的参数,
    //nopgbrk表示没有分页标记,
    //“-”表示直接得到流输出
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
           
            p.Start();
            //输出到textBox1中
            textBox1.Text=p.StandardOutput.ReadToEnd();
            
            p.Close();
        }
    }
}
namespace 利用xpdf提取pcf文档的txt
{
    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";
            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";
            p.StartInfo.FileName = path;
            p.StartInfo.Arguments = string.Format("-nopgbrk " + filename + " -");//调试的时候,看到filename的   //值是正常的
            Console.WriteLine(string.Format("-nopgbrk " + filename + " -"));
            p.StartInfo.UseShellExecute = false;          
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;//同样的程序同样的参数
            p.Start();
            textBox1.Text = p.StandardOutput.ReadToEnd(); 
            p.Close();
        }
        
    }
}