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);
}
}
//傳送打開文件對話框中得到的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();
}
}
}
p.StartInfo.Arguments = string.Format( @"d:\我的文檔\test.pdf" + " -");
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();
}
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。