0

I call a console program in a c# application but it's not working.

I'm trying to call pdf toolkit VIA c#.

When I run pdftk using command prompt, the output file (new.pdf) is created. When c# calls pdftk it doesn't error, but it doesn't work.

Am I calling it wrong in C# or something?

C# Call: (Not working)

System.Diagnostics.Process.Start(pdfTKPath, pdftkArgs);
Console.Write(pdfTKPath + pdftkArgs);
Console.ReadLine();

// Here's the string that the console outputs.
// pdftk.exe C:\Users\name\Desktop\assignment1\assignment1\data\temp\test_cropped.pdf stamp C:\Users\name\Desktop\assignment1\assignment1\data\temp\test_footer.pdf output C:\Users\name\Desktop\assignment1\assignment1\data\temp\new.pdf

CMD Prompt Call: (Works Fine)

C:\Users\name>pdftk.exe c:\Users\name\Desktop\assignment1\assignment1\data\temp\test_cropped.pdf stamp c:\Users\name\Desktop\assignment1\assignment1\data\temp\test_footer.pdf output c:\Users\name\Desktop\assignment1\assignment1\data\temp\new.pdf
Frantumn
  • 1,725
  • 7
  • 36
  • 61

4 Answers4

0
C:\Users\name>pdftk.exe

is wrong

Use the following one:

C:\Users\name\pdftk.exe

Also, did you escape

\

symbol? It is required if you are hardcoding path in the app

Ivan Surzhenko
  • 149
  • 1
  • 8
0

Maybe pdftk.exe is not in the path. Try to call the exe specifying it's full path.

0

firstly I would check if aprocess is created and if it has an error

var processo=System.Diagnostics.Process.Start(pdfTKPath, pdftkArgs);
Console.Write("process created: "+processo.ExitCode);
pomarc
  • 2,194
  • 3
  • 23
  • 30
0

The reason that this wasn't working is that the processing that was happening with the prior method wasn't complete.

The method before this one uses ghost script to create a cropped PDF file. This method was evoked without ghost script completing the work. Therefore this method didn't think the files existed yet (because they didn't). I set this method to wait 2 second before starting and it works fine. This allowed the previous method time to complete.

Frantumn
  • 1,725
  • 7
  • 36
  • 61