Android Open Source - PDF2ImageForEP P D F2 Image Service






From Project

Back to project page PDF2ImageForEP.

License

The source code is released under:

GNU General Public License

If you think the Android project PDF2ImageForEP listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * PDF??????????????????????????????????????????
 * ???????????ClassLoader????????????????????????????????????????????
 * //from  w  ww .j a  va 2s .c  o m
 * 
 * PDF??????????????????????MuPDF????????????????????????????????????
 * http://mupdf.com
 *
 * ???????????????????????????GPLv3?????????????
 */

package jp.co.muratec.pdf2image;

import java.io.File;
import com.artifex.mupdf.MuPDFCore;

import android.graphics.Bitmap;
import android.graphics.PointF;
import android.os.RemoteException;

public class PDF2ImageService {
  // ???????
  public void initLibrary(String appPath,String outPath){
    LoadLibrary instance = LoadLibrary.getInstance();
    instance.init(appPath,outPath);
  }
  
  // ?????????????????????
  private boolean checkSrcPath(String srcPDFPath){
    if( (new File( srcPDFPath )).exists() == false){
      // srcPath??????????????
      return false;
    }
    if(!srcPDFPath.endsWith(".pdf")
    && !srcPDFPath.endsWith(".xps")
    && !srcPDFPath.endsWith(".cbz")
    ){
      // ??????????????
      return false;
    }
    return true;
  }
  
  // ???????????????
  public int checkNeedsPassword(String srcPDFPath){
    if(checkSrcPath(srcPDFPath) == false){
      return -1;
    }
    try {
      MuPDFCore core = new MuPDFCore(srcPDFPath);
      if(core.needsPassword()){
        return 1;
      } else {
        return 0;
      }
    } catch (Exception e) {
      e.printStackTrace();
      return -1;
    }
  }
  
  // ????????
  public int getCount(String srcPDFPath,String password){
    if(checkSrcPath(srcPDFPath) == false){
      return -1;
    }
    try {
      MuPDFCore core = new MuPDFCore(srcPDFPath);
      if(core.needsPassword()){
        // ???????
        if(core.authenticatePassword(password) != true){
          // ????????
          return -2;
        }
      }
      return core.countPages();
    } catch (Exception e) {
      e.printStackTrace();
      return -1;
    }
  }
  
  // ????????????
  public PointF getPDFSize(String srcPDFPath,int page,String password){
    if(checkSrcPath(srcPDFPath) == false){
      return null;
    }
    try {
      MuPDFCore core = new MuPDFCore(srcPDFPath);
      if(core.needsPassword()){
        // ???????
        if(core.authenticatePassword(password) != true){
          // ????????
          return null;
        }
      }
      if(core.countPages() < page){
        // ???????????????
        return null;
      }
      
      return core.getPageSize(page-1);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
  
  // ???????????????????????????????
  public Bitmap getImage(String srcPDFPath, int page, int width,int height,String password) throws RemoteException {
    if(page <= 0){
      return null;
    }
    if(checkSrcPath(srcPDFPath) == false){
      return null;
    }
    
    
    try {
      MuPDFCore core = new MuPDFCore(srcPDFPath);
      if(core.needsPassword()){
        // ???????
        if(core.authenticatePassword(password) != true){
          // ????????
          return null;
        }
      }
      if(core.countPages() < page){
        // ???????????????
        return null;
      }
      
      PointF size = new PointF();
      // ????????
      if(width > 0 && height > 0){
        size.set((float)width, (float)height);
      } else {
        size  = core.getPageSize(page-1);
      }
      double MemorySize = size.x * size.y;            // ?????????
      double freeSize   = (Runtime.getRuntime().freeMemory());  // ?????????????
      if(MemorySize > freeSize){
        // ????????????????????????????????
        double round = Math.sqrt(freeSize / MemorySize);
        size.x  = (float) (round * size.x);
        size.y = (float) (round * size.y);
      }
      return core.drawPage(page-1,(int)size.x, (int)size.y, 0, 0, (int)size.x, (int)size.y);  // PDF???????????????????????
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
  
}




Java Source Code List

com.artifex.mupdf.ChoosePDFActivity.java
com.artifex.mupdf.LinkInfo.java
com.artifex.mupdf.MuPDFActivity.java
com.artifex.mupdf.MuPDFCore.java
com.artifex.mupdf.MuPDFPageAdapter.java
com.artifex.mupdf.MuPDFPageView.java
com.artifex.mupdf.OutlineActivityData.java
com.artifex.mupdf.OutlineActivity.java
com.artifex.mupdf.OutlineAdapter.java
com.artifex.mupdf.OutlineItem.java
com.artifex.mupdf.PageView.java
com.artifex.mupdf.ReaderView.java
com.artifex.mupdf.SafeAsyncTask.java
com.artifex.mupdf.SearchTaskResult.java
jp.co.muratec.pdf2image.DeepRadioGroup.java
jp.co.muratec.pdf2image.FilerActivity.java
jp.co.muratec.pdf2image.LoadLibrary.java
jp.co.muratec.pdf2image.PDF2ImageActivity.java
jp.co.muratec.pdf2image.PDF2ImageService.java