Fondesa Fondesa - 1 year ago 214
Android Question

Android's PdfRenderer class produces low quality images

I'm using

above api 21 to display pdf in my app and I noticed that the quality of pages is very poor.
I followed also google sample to use
and this is how I create
for page:

//mCurrentPage is a PdfRenderer.Page and mImageView is an ImageView
Bitmap bitmap = Bitmap.createBitmap(mCurrentPage.getWidth(),
mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);

I used
because as far as I know, it's the best quality to display bitmaps.
Am i doing something wrong?


This is the huge difference between PdfRenderer class and a classic Pdf reader:

enter image description here enter image description here

Answer Source

ARGB_8888 is for color quality only but the printing/displaying quality is related to the resolution (how much dots per inch you have when displaying on screen).

For example, if you have 400 DPI screen (400 Dots Per Inch) and want to display PDF with this quality then you should render the bitmap the size calculated like this, you can get the device dpi from displaymetrics like this getResources().getDisplayMetrics().densityDpi:

Bitmap bitmap = Bitmap.createBitmap(
    getResources().getDisplayMetrics().densityDpi / 72 * mCurrentPage.getWidth(),                        
    getResources().getDisplayMetrics().densityDpi / 72 * mCurrentPage.getHeight(),

where getResources().getDisplayMetrics().densityDpi is the target resolution, 72 (DPI) is the default PDF resolution. In other words to match the quality of the printing device of the display you should increase the size of the image rendered as default PDF resolution is 72 DPI. Please also check this post?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download