Knowledge Base - Merge two documents (Server)

/**
  * Merges the given 2 files into the output file, (first file followed by the second one)
  *
  * @param firstFile the path of the first document.
  * @param firstPwd the password of the first document.
  * @param secondFile the path of the second document.
  * @param secondPwd the password of the second document.
  * @param outputFile the path of the output document.
  * @return true or false
  */
 public static boolean mergePDF(String firstFile, String firstPwd, String secondFile, String secondPwd, String outputFile) {
  try {
    //init the library and activate the license
    Global.Init(company, email, key);
   
    //create the output file
    Document mOutputDoc = new Document();
    if(mOutputDoc.Create(outputFile) == 0) {
     int destno = 0;
     //import the first file
     Document mInputFile = new Document();
     if(mInputFile.Open(firstFile, firstPwd) == 0) {    
      ImportContext mContext = mOutputDoc.ImportStart(mInputFile);
      if(mContext != null) { //import all pages
       int pagesCount = destno = mInputFile.GetPageCount();
       for(int i = 0; i < pagesCount; i++)
        mOutputDoc.ImportPage(mContext, i, i);
       mContext.Destroy();
      }
     
     }
     mInputFile.Close();
    
     //import the second file
     mInputFile = new Document();
     if(mInputFile.Open(secondFile, secondPwd) == 0) {    
      ImportContext mContext = mOutputDoc.ImportStart(mInputFile);
      if(mContext != null) { //import all pages
       int pagesCount = mInputFile.GetPageCount();
       for(int i = 0; i < pagesCount; i++, destno++)
        mOutputDoc.ImportPage(mContext, i, destno);
       mContext.Destroy();
      }     
     }
     mInputFile.Close();
}
    mOutputDoc.Save();
    mOutputDoc.Close();
    return true;
} catch (Exception e) {
    e.printStackTrace();
   }
   return false;
 }
Applies To

RadaeePDF Master SDK

Details

Created : 2017-05-05 14:11:11, Last Modified : 2017-05-08 15:47:40