- Posts: 7
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
Thumbnails for PDF in grid
IP: 192.168.0.70
12 years 1 month ago #5030
by SONAWANE
Thumbnails for PDF in grid was created by SONAWANE
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.
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.
IP: 192.168.0.70
12 years 1 month ago #5038
by nermeen
IP: 192.168.0.70
12 years 1 month ago #5042
by SONAWANE
Replied by SONAWANE on topic Thumbnails for PDF in grid
I have tried that, every time I'm getting false. So it calls RenderToBmp.
IP: 192.168.0.70
12 years 1 month ago #5045
by rtoshiro
Replied by rtoshiro on topic Thumbnails for PDF in grid
Yes, I have the same problem.
I have not found any solution yet. If you do, plz share.
Best
T
I have not found any solution yet. If you do, plz share.
Best
T
IP: 192.168.0.70
12 years 1 month ago #5047
by SONAWANE
Replied by SONAWANE on topic Thumbnails for PDF in grid
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();
}
}
}
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();
}
}
}
IP: 192.168.0.70
12 years 2 weeks ago #5439
by SONAWANE
Replied by SONAWANE on topic Thumbnails for PDF in grid
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 [email protected]
Note :- To implement this you gonna need at least professional license.
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 [email protected]
Note :- To implement this you gonna need at least professional license.
Time to create page: 0.422 seconds