PdfViewPager icon indicating copy to clipboard operation
PdfViewPager copied to clipboard

PDF file with pages of different dimensions, does not render correctly

Open howelltw opened this issue 6 years ago • 3 comments

The init() method of the BasePDFPagerAdapter class calls a method named extractPdfParamsFromFirstPage. These param are then used to new up a SimpleBitmapPool(params) and assign it to bitmapContainer. This bitmapContainer then has a fixed width and height based on that first page of the PDF. Subsequent pages in the PDF with a different width or height are now distorted when they are rendered.

Changing instantiateItem (from the PDFPagerAdapter class) to compare the next PdfRenderer.Page dimensions with the bitmapContainer dimensions, and then adjusting the width/height of bitmapContainer as needed has fixed the problem for me.

howelltw avatar Jul 17 '19 16:07 howelltw

Indeed. As you very well said. This calculation is done for PDF documents with same size in all pages. If you have a different page size for each page, you need to recalculate page dimensions for each page and render it using these values :)

Thanks for the feedback

voghDev avatar Jul 18 '19 08:07 voghDev

Is there a way we can do that? It looked like the details of the page dimensions and bitmapContainer were not accessible outside of the library.

howelltw avatar Jul 18 '19 22:07 howelltw

Yes, you can subclass the base PDF Pager Adapter and do your own implementation with the page size calculations. You can just copy and paste the original code and modify only the necessary parts. After that you will have to pass your own PdfPagerAdapter subclass to your PdfViewPager

Maybe #16 contains a little more information about this

voghDev avatar Jul 19 '19 05:07 voghDev