Just a quick setup to render a pdf File.
XML Fragment of Image view (somewhere in your layouts xml where you need it)
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorSecondary"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"><ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/pdf_view"
tools:srcCompat="@tools:sample/avatars" /></RelativeLayout>
Dependencies in build.gradle (Module File) [Inside dependencies { } ]
/* PDF LIBRARY AND PHOTOVIEWER ZOOM UPDATE APACHE 2 LICENSE */
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2' /* To Render PDF */
implementation 'com.commit451:PhotoView:1.2.4' /* To zoom and scroll image view */
The Java Code
PdfiumCore pdfiumCore = new PdfiumCore(getApplicationContext());
Uri currenturi = Uri.fromFile(FILE OBJECT WITH PDF FILE);
ParcelFileDescriptor fd = getApplicationContext().getContentResolver().openFileDescriptor(currenturi, "r");
PdfDocument pdfDocument = pdfiumCore.newDocument(fd);/// OPEN FIRST PAGE
pdfiumCore.openPage(pdfDocument, INT_OF_PAGE_TO_OPEN);/// Find Imageview
ImageView img = findViewById(R.id.imageView2);/// GET PAGES OF FILE
int currentPagesOnPDF = pdfiumCore.getPageCount(pdfDocument);/// ADD MULTIPLIERS TO INCREASE THE PDF PIXEL QUALITY
int width = pdfiumCore.getPageWidthPoint(pdfDocument, tmploop); // *2 ? for double pixel size
int height = pdfiumCore.getPageHeightPoint(pdfDocument, tmploop); // *2 ? for double pixel sizeBitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
pdfiumCore.renderPageBitmap(pdfDocument, bmp, INT_OF_PAGE_TO_OPEN, 0, 0, width, height);/// SET RENDERED PAGE TO VIEW
img.setImageBitmap(bmp);//Close Document when render is done
pdfiumCore.closeDocument(pdfDocument);
You can put this code in your mainactivity, you need to apply functions as site-changing and other stuff by yourself...
Tribute to the Programmers:
https://github.com/barteksc/AndroidPdfViewer
https://github.com/chrisbanes/PhotoView