0

I want to convert a pdf file into an html file, so that I can extract the values in a table.

pdftohtml.exe can do this.

If I call the following on a command prompt I get an html page with the content from the pdf file:

pdftohtml.exe test.pdf test.html

This works as expected. Now I want to invoke this exe via C#.

I did the following:

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

Unfortunately this does not work. I suspect that somehow the parameters are not past to the exe correctly.

When I call this exe via the command line with -c before the parameters I get an error:

pdftohtml.exe -c test.pdf test.html

leads to an error (rangecheck in .putdeviceprops).

Does someone know how to correctly invoke this program?

Alexander
  • 420
  • 1
  • 5
  • 17

1 Answers1

1

You can use the following stuff,

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;
}

Usually /C will be used to execute the command and then terminate. In the above code, do modifications as required.

Dineshkumar
  • 1,468
  • 4
  • 22
  • 49
  • This works. But I made another mistake. I did not include the path to the two files in the parameters. The exe console program was not in the same folder as the two files and therefore the program could not find the files. I have now added an absolute path and everything works as expected. That means that my code did work, just the parameters where wrong. Your code works as well. Thanks for the help. – Alexander Jan 21 '14 at 13:29