I am creating an application using PDFRenderer at API 5.0 I had to add pdfrenderer.jar externally also now it show's the following error - "The constructor PDFRenderer(ParcelFileDescriptor) is undefined" Can anyone help... This is new to me..
Android PDFRenderer compiling issue
2k views Asked by Diya At
3
There are 3 answers
6
On
private void render() {
try {
Log.e("In render()","render");
imageView = (ImageView) findViewById(R.id.imageView);
int REQ_WIDTH = 1;
int REQ_HEIGHT = 1;
REQ_WIDTH = imageView.getWidth();
REQ_HEIGHT = imageView.getHeight();
Log.e("In render2()","render2");
System.out.println("req_height"+REQ_HEIGHT+" "+"REQ_WIDTH"+REQ_WIDTH);
Bitmap bitmap = Bitmap.createBitmap(REQ_WIDTH, REQ_HEIGHT, Bitmap.Config.ARGB_4444);
File file = new File("/home/woigames/Desktop/PDF/DebitCards-tc.pdf");
PDFRenderer renderer = new PDFRenderer(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY));
if(renderer != null)
{
Log.i("renderer not null","check");
}
else
{
Log.i("renderer is null","check");
}
final int pageCount = renderer.getPageCount();
if (currentPage < 0) {
currentPage = 0;
} else if (currentPage > renderer.getPageCount()) {
currentPage = renderer.getPageCount() - 1;
}
Matrix m = imageView.getImageMatrix();
Rect rect = new Rect(0, 0, REQ_WIDTH, REQ_HEIGHT);
renderer.openPage(currentPage).render(bitmap, rect, m, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
imageView.setImageMatrix(m);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
renderer.close();
} catch (Exception e) {
e.printStackTrace();
}
Use
PDFRenderer(ParcelFileDescriptor input)
where input is a seekable file descriptor.Pdf Renderer basically takes a file descriptor as its parameter and you havent supplied any.
Refer the developer page https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html