I am trying to convert PDF To image Bitmap.. and for that I am Using this Code Below.
pdfFile = Environment.getExternalStorageDirectory().toString() + "/" + "imagepdf.pdf"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Uri uri = MainActivity.getUriFromFile(PdfExtrectorActivity.this,new File(pdfFile));
final ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(
uri, "r");
final FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
pdfRenderer = new PdfRenderer(parcelFileDescriptor);
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap;
final int pageCount = pdfRenderer.getPageCount();
for (int i = 0; i < pageCount; i++) {
PdfRenderer.Page page = pdfRenderer.openPage(i);
bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
// close the page
page.close();
}
// close the renderer
pdfRenderer.close();
}
when I send ParcelFileDescriptor to pdfRenderer it will throws exception
java.io.IOException: cannot create document. Error: 3
I found Some Link from GitHub issues. https://github.com/googlesamples/android-PdfRendererBasic/issues/15 but it wont help me.
Any Help Accepted. thank you.
my Problem solved with this solutions to convert Image Bitmap from PDF which are in SD card.,
And this will worked fine for me