Today, we investigate a PDF file extraction, merging function, using the following tool (PDFTK):
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
Doing well in Cmd.exe, but in the. NET environment, with a program call to the problem, the calling code is as follows:
Process p =NewProcess (); p.StartInfo.FileName="Cmd.exe"; P.startinfo.useshellexecute=false; P.startinfo.redirectstandardinput=true; P.startinfo.redirectstandardoutput=true; P.startinfo.createnowindow=true; P.start (); //p.standardinput.writeline (@ "pdftk E:\Temp\pdf\11.pdf E:\Temp\pdf\222.pdf Cat output E:\Temp\pdf\3.pdf" + "& Exit ");P.standardinput.writeline (@"pdftk E:\Temp\pdf\11.pdf dump_data|findstr numberofpages"+"&exit"); P.standardinput.autoflush=true; stringresult =P.standardoutput.readtoend (); MessageBox.Show ("ExitCode:"+ P.exitcode +"Result:"+result); p.WaitForExit (10000);
No matter how you debug, the code is stuck in P. Standardoutput.readtoend () Here, if my command is replaced by a similar "ping 127.0.0.1-n 5" Then you can pass,
Ping.exe is also external program, can pass normally, but PDFTK can't, the whole day, finally solved.
The original is less this sentence:
true;
In principle, we don't use the wrong flow, for example: P. Standarderror.readtoend (), can not set this property, but PDFTK is so weird,
Presumably the error stream was used in the output stream? Alas, the reason is no longer fine, solve the problem is good, in general, it is best to set these three attributes together to True, buy a lesson.
true ; true ; true;
Call Cmd.exe to perform a merge of PDFs (Pdftk.exe)