c#中利用xpdf提取pdf文档中文本内容的一个小麻烦(100分) 本帖最后由 liuqinglei6666 于 2009-09-25 15:49:24 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下断点 看看你传的参数filename 是什么 我调试了几次,确实是取得了一个完整的文件名,就是也能得到如:d:\\我的文档\\test.pdf这样的filename 我下载了一个测试了一下。好像没有问题啊。我的代码,在你的基础上作了小修改。就是在文件名两边加上"",防止路径中有空格。但是你测试的路径没有空格,因此应该不是这个原因。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(); } } 呵呵,谢谢楼上的兄台,下载的xpdf中xpdftotext.exe用到的配置文件xpdfrc需要手动配置,我如果把那些字体啊,什么的映射成绝对路径下的文件,就不会出现上面的问题,但是我把配置文件中的路径改成了相对路径,于是就出现了上面的问题了,看兄台能够很轻易的就运行成功,一定是做过很多代码的,这里还得劳烦兄台再给看一下,帮下忙,能遇到一个大神不容易,大神可不能吝啬啊,先谢过了哈 两个表关联的水晶报表 odbc读取DB数据库的问题 将ACCESS数据导入SQL的语句错误问题 winform不同窗口如何传递参数的问题。。。。??? 用DataSet更新数据库有错误。。。。。 关于Socket的问题 谁能指导我一下交错数组???? C#中这个里面的小窗口怎么建 C#控件中如何获得属性变化前的时机?(内详) 关于字符相加 请问数据库的实体类需要序列化吗?有什么作用 C# 连接oracle数据库
我的代码,在你的基础上作了小修改。就是在文件名两边加上"",防止路径中有空格。
但是你测试的路径没有空格,因此应该不是这个原因。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(); }
}