Java Merge Pdf,itext.jar

Source: Internet
Author: User

Far from the original: http://illy.iteye.com/blog/856479

We sometimes need to merge multiple PDF files into one. GUI tools just don't say it,
This only discusses how to merge PDFs using Java programs. We just need to use the Itext.jar to get the job done.

ImportJava.io.FileOutputStream; Importjava.io.IOException; Importcom.lowagie.text.Document; Importcom.lowagie.text.DocumentException; Importcom.lowagie.text.pdf.PdfCopy; ImportCom.lowagie.text.pdf.PdfImportedPage; ImportCom.lowagie.text.pdf.PdfReader;  Public classMergefile { Public Static voidMain (string[] args) {string[] files= {"E:\\1.pdf", "E:\\2.pdf", "E:\\3.pdf" }; String Savepath= "E:\\temp.pdf";      Mergepdffiles (Files, savepath); } /** * Close and PDF file * * @param files to fit and file number (absolute path such as {"E:\\1.pdf", "e:\\2.pdf", * "E:\\3.pdf"}) * @param new File * and the new files are definitely the path of the e:\\temp.pdf, please delete the files that are no longer used after use * @return Boolean to return true successfully, or false */         Public Static Booleanmergepdffiles (string[] files, String newfile) {BooleanRetValue =false; Document Document=NULL; Try{document=NewDocument (NewPdfreader (Files[0]). GetPageSize (1)); Pdfcopy Copy=NewPdfcopy (document,NewFileOutputStream (NewFile));              Document.open ();  for(inti = 0; i < files.length; i++) {Pdfreader reader=NewPdfreader (Files[i]); intn =reader.getnumberofpages ();  for(intj = 1; J <= N; J + +) {document.newpage (); Pdfimportedpage page=Copy.getimportedpage (Reader, J);                  Copy.addpage (page); }} RetValue=true; } Catch(Exception e) {e.printstacktrace (); } finally{document.close (); }          returnRetValue; }  }  

Itextasian.jar Itext-1.3.jar

Java Merge Pdf,itext.jar

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.