Android Open Source - RadaeePDF-B4A P D F Crop






From Project

Back to project page RadaeePDF-B4A.

License

The source code is released under:

Apache License

If you think the Android project RadaeePDF-B4A 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

package com.radaee.reader;
import com.radaee.pdf.*;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
//  w  w  w. j  ava2  s .  co  m
/**
 * test view<br/>
 * this view clip one page as 100*100 blocks.<br/>
 * every block is a DIB data.
 * @author Radaee
 *
 */
public class PDFCrop extends View
{
  private Document m_doc = null;
  static private final int blk_w = 100;
  static private final int blk_h = 100;
  static private final float ratio = 1.0f;
  private int dibs[][];
  Bitmap bitmap;
  public PDFCrop(Context context)
  {
    super(context);
  }
  public PDFCrop(Context context, AttributeSet attrs)
  {
    super(context, attrs);
  }
  public void open( Document doc )
  {
    m_doc = doc;
    Page page = m_doc.GetPage(0);
    float w = m_doc.GetPageWidth(0) * ratio;
    float h = m_doc.GetPageHeight(0) * ratio;
    bitmap = Bitmap.createBitmap((int)w, (int)h, Config.ARGB_8888);
    bitmap.eraseColor(0xFFFFFFFF);
    int wcnt = (int)(w + blk_w - 1) / blk_w;
    int hcnt = (int)(h + blk_h - 1) / blk_h;
    dibs = new int[hcnt][wcnt];
    int y = 0;
    int hi = 0;
    while( hi < hcnt )
    {
      int x = 0;
      int wi = 0;
      while( wi < wcnt )
      {
        dibs[hi][wi] = Global.dibGet(0, blk_w, blk_h);
        Matrix mat = new Matrix(ratio, -ratio, -x, h - y);
        page.RenderPrePare(dibs[hi][wi]);
        page.Render(dibs[hi][wi], mat);
        mat.Destroy();
        x += blk_w;
        wi++;
      }
      y += blk_h;
      hi++;
    }
    page.Close();
  }
  public void close()
  {
    float w = m_doc.GetPageWidth(0) * ratio;
    float h = m_doc.GetPageHeight(0) * ratio;
    int wcnt = (int)(w + blk_w - 1) / blk_w;
    int hcnt = (int)(h + blk_h - 1) / blk_h;
    int hi = 0;
    while( hi < hcnt )
    {
      int wi = 0;
      while( wi < wcnt )
      {
        Global.dibFree(dibs[hi][wi]);
        wi++;
      }
      hi++;
    }
    m_doc = null;
    bitmap.recycle();
  }
  protected void onDraw( Canvas canvas )
  {
    if( m_doc != null )
    {
      int bmp = Global.lockBitmap(bitmap);
      float w = m_doc.GetPageWidth(0) * ratio;
      float h = m_doc.GetPageHeight(0) * ratio;
      int wcnt = (int)(w + blk_w - 1) / blk_w;
      int hcnt = (int)(h + blk_h - 1) / blk_h;
      int y = 0;
      int hi = 0;
      while( hi < hcnt )
      {
        int x = 0;
        int wi = 0;
        while( wi < wcnt )
        {
          Global.drawToBmp(bmp, dibs[hi][wi], x, y);
          x += blk_w;
          wi++;
        }
        y += blk_h;
        hi++;
      }
      Global.unlockBitmap(bitmap, bmp);
      canvas.drawBitmap(bitmap, 0, 0, null);
    }
  }
}




Java Source Code List

com.example.pdfhttpdemo.MainActivity.java
com.example.pdfhttpdemo.ReaderController.java
com.radaee.pdf.BMDatabase.java
com.radaee.pdf.BMDatabase.java
com.radaee.pdf.BMDatabase.java
com.radaee.pdf.Document.java
com.radaee.pdf.Document.java
com.radaee.pdf.Document.java
com.radaee.pdf.Global.java
com.radaee.pdf.Global.java
com.radaee.pdf.Global.java
com.radaee.pdf.HWriting.java
com.radaee.pdf.HWriting.java
com.radaee.pdf.HWriting.java
com.radaee.pdf.Ink.java
com.radaee.pdf.Ink.java
com.radaee.pdf.Ink.java
com.radaee.pdf.Matrix.java
com.radaee.pdf.Matrix.java
com.radaee.pdf.Matrix.java
com.radaee.pdf.PDFHttpStream.java
com.radaee.pdf.PageContent.java
com.radaee.pdf.PageContent.java
com.radaee.pdf.PageContent.java
com.radaee.pdf.Page.java
com.radaee.pdf.Page.java
com.radaee.pdf.Page.java
com.radaee.pdf.Path.java
com.radaee.pdf.Path.java
com.radaee.pdf.Path.java
com.radaee.reader.PDFCropAct.java
com.radaee.reader.PDFCrop.java
com.radaee.reader.PDFEncAct.java
com.radaee.reader.PDFInkAct.java
com.radaee.reader.PDFInk.java
com.radaee.reader.PDFReaderAct.java
com.radaee.reader.PDFReaderOldAct.java
com.radaee.reader.PDFReaderOld.java
com.radaee.reader.PDFReader.java
com.radaee.reader.PDFSimpleAct.java
com.radaee.reader.PDFSimple.java
com.radaee.reader.PDFTestAct.java
com.radaee.reader.ReaderActivity.java
com.radaee.reader.ReaderController.java
com.radaee.reader.ReaderController.java
com.radaee.util.ComboListAdt.java
com.radaee.util.ComboList.java
com.radaee.util.PDFAESEnc.java
com.radaee.util.PDFAESEnc.java
com.radaee.util.PDFAESStream.java
com.radaee.util.PDFAESStream.java
com.radaee.util.PDFAssetStream.java
com.radaee.util.PDFAssetStream.java
com.radaee.util.PDFFileStream.java
com.radaee.util.PDFFileStream.java
com.radaee.util.PDFGridAdt.java
com.radaee.util.PDFGridItem.java
com.radaee.util.PDFGridThread.java
com.radaee.util.PDFGridView.java
com.radaee.util.PDFHttpStream.java
com.radaee.util.PDFHttpStream.java
com.radaee.util.PDFMemStream.java
com.radaee.util.PDFMemStream.java
com.radaee.util.PDFThumbView.java
com.radaee.util.SnatchAdt.java
com.radaee.util.SnatchView.java
com.rootsoft.pdfviewer.main.java
com.rootsoft.pdfviewer.readercontroller.java
com.rootsoft.rspdfviewer.pdf.RSPDFAnnotation.java
com.rootsoft.rspdfviewer.pdf.RSPDFBMDatabase.java
com.rootsoft.rspdfviewer.pdf.RSPDFDocument.java
com.rootsoft.rspdfviewer.pdf.RSPDFGlobal.java
com.rootsoft.rspdfviewer.pdf.RSPDFHWriting.java
com.rootsoft.rspdfviewer.pdf.RSPDFInk.java
com.rootsoft.rspdfviewer.pdf.RSPDFMatrix.java
com.rootsoft.rspdfviewer.pdf.RSPDFPageContent.java
com.rootsoft.rspdfviewer.pdf.RSPDFPage.java
com.rootsoft.rspdfviewer.pdf.RSPDFPath.java
com.rootsoft.rspdfviewer.pdf.RSPDFTemplate.java
com.rootsoft.rspdfviewer.pdf.RSPDFVPage.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewCurl.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewDual.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewHorz.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewThumb.java
com.rootsoft.rspdfviewer.pdf.RSPDFViewVert.java
com.rootsoft.rspdfviewer.pdf.RSPDFView.java
com.rootsoft.rspdfviewer.pdf.RSReaderView.java