Call Cmd.exe to perform a merge of PDFs (Pdftk.exe)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.