0

I'm very new to c# and for a project I've downloaded some code Authored by tixiv from https://www.das-labor.org/trac/browser/microcontroller/src-atmel/laserExposer/PC_Frontend?order=name

I'm trying to open a pdf file within a form.

The error I'm getting is:

An exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll but was not handled in user code Additional information: The system cannot find the file specified If there is a handler for this exception, the program may be safely continued.

Question 1.
I am confused by the line:

p.StartInfo.FileName = "E:/Test/test2.pdf";

can I use an empty string or do I need to define a specific file and location as above?

Question 2. What do the switches (-f 1 -l 1 -r 600) in the following statement mean?

p.StartInfo.Arguments = "-mono -f 1 -l 1 -r 600 " + openPdfDialog.FileName + " E:/Documents/Eagle Projects/Testing/";

Question 3. What is the correct way to catch this exception?

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
    Process p = new Process();
    // Redirect the output stream of the child process.
    // StartInfo Gets or sets the properties to pass to the Start method of the Process.
    p.StartInfo.UseShellExecute = false;                    // UseShellExecute Setting this property to false enables you to redirect input, output, and error streams.
    p.StartInfo.RedirectStandardOutput = true;              // true if output should be written to Process.StandardOutput;
    p.StartInfo.FileName = "E:/Test/test2.pdf";             // The default is an empty string.
    p.StartInfo.Arguments = "-mono -f 1 -l 1 -r 600 " + openPdfDialog.FileName + " E:/Documents/Eagle Projects/Testing/";
    p.Start();
    // Do not wait for the child process to exit before
    // reading to the end of its redirected stream.

    // Read the output stream first and then wait.
    string output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();


    FileInfo f = new FileInfo("c:\\Windows\\Temp\\-000001.pbm");
    StreamReader s = f.OpenText();
    ...
Lemonseed
  • 1,644
  • 1
  • 15
  • 29
rwvb
  • 15
  • 3
  • is this running on a local machine .. try changing the path for the filename to something like this `p.StartInfo.FileName = @"E:\Test\test2.pdf";` do you know what this `@` means? it's string Literal if you are not familiar do a quick google search – MethodMan Feb 09 '16 at 21:00
  • added @"E:\Test\test2.pdf and it changed the error info **Additional information: The specified executable is not a valid application for this OS platform.** I'm not sure if this is an improvement or not? @MethodMan – rwvb Feb 09 '16 at 21:42
  • take a look at this http://stackoverflow.com/questions/1423922/open-a-pdf-file-programmatically-at-a-named-destination – terbubbs Feb 09 '16 at 21:52
  • I have read the post so I can see that you can pass parameters to the open command using the /A switch but what is the meaning of the switches in the above code i.e. -f 1 -l 1 -r 600. Does this still apply when inside the form container? @terbubbs – rwvb Feb 09 '16 at 22:13

1 Answers1

0

You may want to check out the link C# System.diagnostics.process.startinfo . But regarding you questions:

1) It seems strange that the input is E:\Test\test2.pdf, rather it should be the process to be executed, like the linked example for HelloWorld.exe. I looked at the repository of your post and it was pdftoppm instead.

2) It's actually input parameter for the pdftoppm, you can find info at pdftoppm linux man page

  • Thank you! You are quite correct, the input should be an exequtable file.That explains a lot... – rwvb Feb 11 '16 at 04:12