PdfView in Android

In questo esempio andremo a creare un semplice Visualizzatore PDF ulilizzando la cartella Assets dove andiamo a caricare il nostro file.
Aggiungiamo la seguente dipendenza al build.gradler:
implementation ‘com.github.barteksc:android-pdf-viewer:2.8.2′
Adesso andiamo a creare il nostro layout:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:gravity=”center”
android:orientation=”vertical”>

<com.github.barteksc.pdfviewer.PDFView
        android:layout_width=”match_parent”
        android:layout_height=”match_parent”
        android:id=”@+id/pdf”/>
</LinearLayout>

MainActivity.java
package com.example.pdf.activities;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.example.pdf.R;
import com.github.barteksc.pdfviewer.*;
import com.github.barteksc.pdfviewer.scroll.*;
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

PDFView pdfView = findViewById(R.id.pdf);
pdfView.fromAsset(“filePdf”)
.swipeHorizontal(true)
.scrollHandle(new DefaultScrollHandle(this))
.load();
}
}