Android Open Source - RadaeePDF-B4A P D F Simple






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;
/*from ww  w.  j  a v  a  2s  . c o  m*/
import com.radaee.pdf.*;
import com.radaee.util.PDFFileStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.util.AttributeSet;
import android.view.View;

/**
 * simplest PDF sample.
 * @author radaee
 */
public class PDFSimple extends View
{
  private Document m_doc = null;
  private PDFFileStream m_stream = null;
  private float m_ratio = 1;
  private int m_pageno = 0;
  private int win_cx = 0;
  private int win_cy = 0;
  private int page_x = 0;
  private int page_y = 0;
  private Bitmap bitmap = null;
  public PDFSimple(Context context)
  {
    super(context);
  }
  public PDFSimple(Context context, AttributeSet attrs)
  {
    super(context, attrs);
  }
  public void Close()
  {
    if( m_doc != null )
    {
      m_doc.Close();
      m_doc = null;
    }
    if( m_stream != null )
    {
      m_stream.close();
      m_stream = null;
    }
    if( bitmap != null )
    {
      bitmap.recycle();
      bitmap = null;
    }
  }
  private void render_page( int pageno )
  {
    if( m_doc != null && bitmap != null )
    {
      bitmap.eraseColor(0xFFFFFFFF);
      Page page = m_doc.GetPage(pageno);
      if( page != null )
      {
        Matrix mat = new Matrix(m_ratio, -m_ratio, 0, m_doc.GetPageHeight(0) * m_ratio);
        page.RenderToBmp(bitmap, mat);
        /*
        int cnt = page.GetAnnotCount();
        for(int x = 0; x < cnt; ++x)
        {
          int handle = page.GetAnnot(x);
          int type = page.GetAnnotFieldType(handle);
          if( type == 4 )
          {
            Toast.makeText(getContext(), "Signature Found", Toast.LENGTH_SHORT).show();
          }
        }
        */
        mat.Destroy();
        page.Close();
      }
      /*
       * Page page = m_doc.GetPage(pageno); if( page != null ) { Matrix
       * mat = new Matrix(m_ratio, -m_ratio, 0, m_doc.GetPageHeight(0) *
       * m_ratio); page.RenderToBmp(bitmap, mat); float rect[] = new
       * float[4]; rect[0] = 100; rect[1] = 80; rect[2] = rect[0] + 100;
       * rect[3] = rect[1] + 20; page.AddAnnotEditbox(mat, rect, 18, 0);
       * mat.Destroy(); page.Close(); m_doc.Save(); }
       */
    }
  }
  public int Open( String path )
  {
    Close();
    m_doc = new Document();
    m_stream = new PDFFileStream();
    boolean ok = m_stream.open(path);
    if( !ok ) return -1;
    int ret = m_doc.OpenStream(m_stream, null);
    if( ret != 0 )
    {
      m_doc.Close();
      m_doc = null;
      return ret;
    }
    onSizeChanged(win_cx, win_cy, 0, 0);
    return 0;
  }
  protected void onSizeChanged (int w, int h, int oldw, int oldh)
  {
    if( w > 0 && h > 0 )
    {
      win_cx = w;
      win_cy = h;
      if( bitmap != null ) bitmap.recycle();
      bitmap = Bitmap.createBitmap(win_cx, win_cy, Config.ARGB_8888);
      render_page(m_pageno);
    }
  }
  protected void onDraw( Canvas canvas )
  {
    if( bitmap != null )
      canvas.drawBitmap(bitmap, page_x, page_y, 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