コード例 #1
0
  private void showPage(int page, float zoom) throws Exception {
    long startTime = System.currentTimeMillis();
    long middleTime = startTime;
    try {
      // free memory from previous page
      mGraphView.setPageBitmap(null);
      mGraphView.updateImage();

      mPdfPage = mPdfFile.getPage(page, true);
      int num = mPdfPage.getPageNumber();
      int maxNum = mPdfFile.getNumPages();
      float wi = mPdfPage.getWidth();
      float hei = mPdfPage.getHeight();
      String pageInfo =
          new File(pdffilename).getName() + " - " + num + "/" + maxNum + ": " + wi + "x" + hei;
      mGraphView.showText(pageInfo);
      Log.i(TAG, pageInfo);
      RectF clip = null;
      middleTime = System.currentTimeMillis();
      Bitmap bi = mPdfPage.getImage((int) (wi * zoom), (int) (hei * zoom), clip, true, true);
      mGraphView.setPageBitmap(bi);
      mGraphView.updateImage();
    } catch (Throwable e) {
      Log.e(TAG, e.getMessage(), e);
      mGraphView.showText("Exception: " + e.getMessage());
    }
    long stopTime = System.currentTimeMillis();
    mGraphView.pageParseMillis = middleTime - startTime;
    mGraphView.pageRenderMillis = stopTime - middleTime;
  }
コード例 #2
0
 private synchronized void startRenderThread(final int page, final float zoom) {
   if (backgroundThread != null) return;
   mGraphView.showText("reading page " + page + ", zoom:" + zoom);
   backgroundThread =
       new Thread(
           new Runnable() {
             @Override
             public void run() {
               try {
                 if (mPdfFile != null) {
                   //			        	File f = new File("/sdcard/andpdf.trace");
                   //			        	f.delete();
                   //			        	Log.e(TAG, "DEBUG.START");
                   //			        	Debug.startMethodTracing("andpdf");
                   showPage(page, zoom);
                   //			        	Debug.stopMethodTracing();
                   //			        	Log.e(TAG, "DEBUG.STOP");
                 }
               } catch (Exception e) {
                 Log.e(TAG, e.getMessage(), e);
               }
               backgroundThread = null;
             }
           });
   updateImageStatus();
   backgroundThread.start();
 }
コード例 #3
0
 private void parsePDF(String filename, String password) throws PDFAuthenticationFailureException {
   long startTime = System.currentTimeMillis();
   try {
     File f = new File(filename);
     long len = f.length();
     if (len == 0) {
       mGraphView.showText("file '" + filename + "' not found");
     } else {
       mGraphView.showText("file '" + filename + "' has " + len + " bytes");
       openFile(f, password);
     }
   } catch (PDFAuthenticationFailureException e) {
     throw e;
   } catch (Throwable e) {
     e.printStackTrace();
     mGraphView.showText("Exception: " + e.getMessage());
   }
   long stopTime = System.currentTimeMillis();
   mGraphView.fileMillis = stopTime - startTime;
 }
コード例 #4
0
  /**
   * Open a specific pdf file. Creates a DocumentInfo from the file, and opens that.
   *
   * <p><b>Note:</b> Mapping the file locks the file until the PDFFile is closed.
   *
   * @param file the file to open
   * @throws IOException
   */
  public void openFile(File file, String password) throws IOException {
    // first open the file for random access
    RandomAccessFile raf = new RandomAccessFile(file, "r");

    // extract a file channel
    FileChannel channel = raf.getChannel();

    // now memory-map a byte-buffer
    ByteBuffer bb = ByteBuffer.NEW(channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()));
    // create a PDFFile from the data
    if (password == null) mPdfFile = new PDFFile(bb);
    else mPdfFile = new PDFFile(bb, new PDFPassword(password));

    mGraphView.showText("Anzahl Seiten:" + mPdfFile.getNumPages());
  }
コード例 #5
0
  private void showPage(int page, float zoom) throws Exception {
    // long startTime = System.currentTimeMillis();
    // long middleTime = startTime;
    try {
      // free memory from previous page
      mGraphView.setPageBitmap(null);
      mGraphView.updateImage();

      // Only load the page if it's a different page (i.e. not just changing the zoom level)
      if (mPdfPage == null || mPdfPage.getPageNumber() != page) {
        mPdfPage = mPdfFile.getPage(page, true);
      }
      // int num = mPdfPage.getPageNumber();
      // int maxNum = mPdfFile.getNumPages();
      float width = mPdfPage.getWidth();
      float height = mPdfPage.getHeight();
      // String pageInfo= new File(pdffilename).getName() + " - " + num +"/"+maxNum+ ": " + width +
      // "x" + height;
      // mGraphView.showText(pageInfo);
      // Log.i(TAG, pageInfo);
      RectF clip = null;
      // middleTime = System.currentTimeMillis();
      Bitmap bi = mPdfPage.getImage((int) (width * zoom), (int) (height * zoom), clip, true, true);
      mGraphView.setPageBitmap(bi);
      mGraphView.updateImage();

      writeTempFileToDisc(bi);
      //   bi.recycle();//ADDED FOR EFFICIENCY

      File dir = Environment.getExternalStorageDirectory();
      File file = new File(dir, IMAGE_PATH + mPage + ".jpg");
      mImageUri = Uri.fromFile(file);
      System.out.println("Displaying " + mImageUri.getPath());
      mAllShareService.start(mImageUri.getPath());

      if (progress != null) progress.dismiss();
    } catch (Throwable e) {
      Log.e(TAG, e.getMessage(), e);
      mGraphView.showText("Exception: " + e.getMessage());
    }
    // long stopTime = System.currentTimeMillis();
    // mGraphView.pageParseMillis = middleTime-startTime;
    // mGraphView.pageRenderMillis = stopTime-middleTime;
  }