RadaeePDF.com :: Topic: Thumbnails for PDF in grid (1/1)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF

TOPIC: Thumbnails for PDF in grid

Thumbnails for PDF in grid 3 years 5 months ago #5030

  • SONAWANE
  • SONAWANE's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Karma: 0
Please can any one help me here, I have tried everything to show PDF thumbnails in grid format.
I have achieved it by using RenderToBmp but its tacking too much of time. So if someone can help me with please. Thanks in advance.:)
The administrator has disabled public write access.

Thumbnails for PDF in grid 3 years 5 months ago #5038

  • nermeen
  • nermeen's Avatar
  • OFFLINE
  • Moderator
  • Posts: 656
  • Thank you received: 37
  • Karma: 17
The administrator has disabled public write access.

Thumbnails for PDF in grid 3 years 5 months ago #5042

  • SONAWANE
  • SONAWANE's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Karma: 0
I have tried that, every time I'm getting false. So it calls RenderToBmp.
The administrator has disabled public write access.

Thumbnails for PDF in grid 3 years 5 months ago #5045

  • rtoshiro
  • rtoshiro's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Karma: 0
Yes, I have the same problem.
I have not found any solution yet. If you do, plz share.

Best
T
The administrator has disabled public write access.

Thumbnails for PDF in grid 3 years 5 months ago #5047

  • SONAWANE
  • SONAWANE's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Karma: 0
I have created my own custom class to to create grid in popup to show thumbnail, but as I said that was not the perfect way to solve it. If want then below is code, just use any layout file with gridView in it. This class show first some pages and in background it keeps on updating grid for more thumb's.

To call this class use startActivityForResult() and pass path of pdf file. onItemClick will return you position to jump on certain page.


import java.util.ArrayList;
import java.util.List;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.example.flipickviewer.R;
import com.radaee.pdf.Document;
import com.radaee.pdf.Matrix;
import com.radaee.pdf.Page;

public class ThumbsViewActivity extends Activity {

private String m_path;
private GridView pdfGridView;
private Context context;
// private PDFGridItem gridItem;
private List<Bitmap> bitmaps;
private GridAdapter adapter;
private Document doc = null;
private Page page = null;
private int MIM_PAGE_READ = 10;
private int LAST_PAGE_READ = 0;
int size = 0, start_position = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.thumbs_layout);
setupUI();
ProgressDialog dialog = new ProgressDialog(context);
dialog.show();
bitmaps = new ArrayList<Bitmap>();
adapter = new GridAdapter();
pdfGridView.setAdapter(adapter);
pdfGridView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent returnIntent = new Intent();
returnIntent.putExtra("result", arg2);
setResult(RESULT_OK, returnIntent);
finish();
}
});
long beginRender = System.currentTimeMillis();
if (doc.Open(m_path, null) == 0) {
size = doc.GetPageCount();
if (doc.GetPageCount() >= MIM_PAGE_READ)
size = MIM_PAGE_READ;
start_position = LAST_PAGE_READ;
for (int count = start_position; count < (size + start_position); count++) {
if (count <= doc.GetPageCount()) {
bitmaps.add(render(count));
LAST_PAGE_READ += 1;
}
}
adapter.notifyDataSetChanged();
new UpdateListViewForThumbs().execute();
}

Log.i("LOGTAG", "rendered time: "
+ (System.currentTimeMillis() - beginRender));
Log.i("LOGTAG", "m_path: " + m_path);
if (dialog.isShowing())
dialog.dismiss();
}

private void setupUI() {
context = this;

pdfGridView = (GridView) findViewById(R.id.pdf_grid_view);
doc = new Document();
m_path = getIntent().getStringExtra("m_page");
}

@Override
public void onBackPressed() {
this.finish();
}

protected Bitmap render(int count) {
Bitmap bmp = null, bitmap = null;

page = doc.GetPage(count);
float w = doc.GetPageWidth(count);
float h = doc.GetPageHeight(count);
Display display = ((Activity) context).getWindowManager()
.getDefaultDisplay();
Point screen_size = new Point();
display.getSize(screen_size);
int width = screen_size.x;
int height = screen_size.y;
int iw = (int) (width * 0.19);
int ih = (int) (height * 0.19);

try {
bmp = Bitmap.createBitmap(iw, ih, Bitmap.Config.ARGB_8888);
bmp.eraseColor(0);
float ratiox = iw / w;
float ratioy = ih / h;
if (ratiox > ratioy)
ratiox = ratioy;
if (!page.RenderThumb(bmp)) {
Canvas canvas = new Canvas(bmp);
Paint paint = new Paint();
paint.setARGB(255, 255, 255, 255);
canvas.drawRect((iw - w * ratiox) / 2, (ih - h * ratiox) / 2,
(iw + w * ratiox) / 2, (ih + h * ratiox) / 2, paint);
Matrix mat = new Matrix(ratiox, -ratiox, (iw - w * ratiox) / 2,
(ih + h * ratiox) / 2);
boolean is_render = page.RenderToBmp(bmp, mat);
if (is_render) {
bitmap = bmp;
}
mat.Destroy();
if (!page.RenderIsFinished()) {
bmp.recycle();
bmp = null;
}
}
} catch (Exception e) {
}

return bitmap;
}

class GridAdapter extends BaseAdapter {

public int getCount() {
return bitmaps.size();
}

public Object getItem(int position) {
// TODO Auto-generated method stub
return bitmaps.get(position);
}

public long getItemId(int position) {
return 0;
}

public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = new ImageView(context);
((ImageView) convertView)
.setLayoutParams(new GridView.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
((ImageView) convertView)
.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
((ImageView) convertView).setImageBitmap(bitmaps.get(position));
return convertView;
}
}

class UpdateListViewForThumbs extends AsyncTask<String, String, String> {

@Override
protected String doInBackground(String... params) {
size = doc.GetPageCount();
start_position = LAST_PAGE_READ;
for (int count = start_position; count < size; count++) {
if (count <= doc.GetPageCount()) {
bitmaps.add(render(count));
LAST_PAGE_READ += 1;
publishProgress("");
}
}

page.Close();
doc.Close();

return null;
}

@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
if (adapter != null)
adapter.notifyDataSetChanged();
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (adapter != null)
adapter.notifyDataSetChanged();
}

}

}
The administrator has disabled public write access.

Thumbnails for PDF in grid 3 years 4 months ago #5439

  • SONAWANE
  • SONAWANE's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Karma: 0
Hello guy's I have modified PDFViewThumb.java for thumbnail grid view.
It also allow user to make it auto_fit as per the view width, or user can also mention column number to keep it fixed. So if someone need this particular class feel free to contact me on This email address is being protected from spambots. You need JavaScript enabled to view it.

Note :- To implement this you gonna need at least professional license.
The administrator has disabled public write access.
Powered by Kunena Forum