【问题标题】:Invoke pdftohtml.exe via C#通过 C# 调用 pdftohtml.exe
【发布时间】:2014-01-21 12:25:31
【问题描述】:

我想把一个pdf文件转换成一个html文件,这样我就可以提取表格中的值了。

pdftohtml.exe 可以做到这一点。

如果我在命令提示符下调用以下命令,我会得到一个包含 pdf 文件内容的 html 页面:

pdftohtml.exe test.pdf test.html

这按预期工作。现在我想通过 C# 调用这个 exe。

我做了以下事情:

string filename = @"C:\Temp\pdftohtml.exe";
Process proc = Process.Start(filename, "test.pdf test.html");

不幸的是,这不起作用。我怀疑以某种方式参数没有正确传递给 exe。

当我通过命令行在参数前使用 -c 调用此 exe 时,我得到一个错误:

pdftohtml.exe -c test.pdf test.html

导致错误(.putdeviceprops 中的范围检查)。

有人知道如何正确调用这个程序吗?

【问题讨论】:

  • 你怎么知道第一个命令不起作用?

标签: c# pdf ocr invoke


【解决方案1】:

你可以使用以下的东西,

using System.Diagnostics;

// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments, everything you would enter after the executable name itself
start.Arguments = arguments; 
// Enter the executable to run, including the complete path
start.FileName = ExeName;
// Do you want to show a console window?
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;

// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
 proc.WaitForExit();

 // Retrieve the app's exit code
 exitCode = proc.ExitCode;
}

通常是/C will be used to execute the command and then terminate。在上面的代码中,根据需要进行修改。

【讨论】:

  • 这行得通。但我又犯了一个错误。我没有在参数中包含两个文件的路径。 exe 控制台程序与这两个文件不在同一个文件夹中,因此程序无法找到这些文件。我现在添加了一个绝对路径,一切都按预期工作。这意味着我的代码确实有效,只是参数错误。您的代码也可以正常工作。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-03
  • 1970-01-01
  • 2018-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多