Knowledge Base - Duplicate page (Server)

 /**
  * creates a copy of the input file into the output file, and readd the given page at the end of the output file.
  *
  * @param inputFile the path of the input document.
  * @param password the password of the input document.
  * @param outputFile the path of the output document.
  * @param pageToDuplicate the page to remove (0-based from 0 to GetPageCount() - 1)
  * @return true or false
  */
 public static boolean duplicatePage(String inputFile, String password, String outputFile, int pageToDuplicate) {
try {
    //init the library and activate the license
    Global.Init(company, email, key);
    
    //open the input file
    Document mInputFile = new Document();
    if(mInputFile.Open(inputFile, password) == 0) {
     //create the output file
     Document mOutputDoc = new Document();
     if(mOutputDoc.Create(outputFile) == 0) {
      ImportContext mContext = mOutputDoc.ImportStart(mInputFile);
      if(mContext != null) { //import all pages
       int pagesCount = mInputFile.GetPageCount();
       for(int i = 0; i < pagesCount; i++)
        mOutputDoc.ImportPage(mContext, i, i);
       mContext.Destroy();
      
       //destroy the old import context, and create a new one
       if(pageToDuplicate >= 0 && pageToDuplicate < pagesCount) { //now re-import the page to duplicate
        mContext = mOutputDoc.ImportStart(mInputFile);
        mOutputDoc.ImportPage(mContext, pageToDuplicate, pagesCount);
        mContext.Destroy();
       }
      }
      mOutputDoc.Save();
      mOutputDoc.Close();
     }
    }
    mInputFile.Close();
    return true;
   } catch (Exception e) {
    e.printStackTrace();
   }
   return false;
 }
Applies To

RadaeePDF Master SDK

Details

Created : 2017-05-05 14:34:57, Last Modified : 2017-05-08 15:48:24