Knowledge Base - Remove page (Server)

/**
 * creates a copy of the input file into the output file without the page to remove.
 *
 * @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 pageToRemove the page to remove (0-based from 0 to GetPageCount() - 1)
 * @return true or false
 */
public static boolean removePage(String inputFile, String password, String outputFile, int pageToRemove) {
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 except for the page to remove
      int dstno = 0;
      for(int i = 0; i < mInputFile.GetPageCount(); i++)
       if(i != pageToRemove && mOutputDoc.ImportPage(mContext, i, dstno))
        dstno++;
      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:26:13, Last Modified : 2017-05-08 15:47:30