Native Mobile App Development With Java

Android pdf viewer URL and Asset folder example

23-Sep-2024

Android pdf viewer URL and Asset folder example


1/ Add dependecy of Pdf view 


implementation 'com.github.DImuthuUpe:AndroidPdfViewer:3.1.0-beta.1'

2/  Add maven on (settings.gradle)


maven { url 'https://jitpack.io' }

3/  Enable jetifier on gradle.properties


android.enableJetifier=true

4/  add xml file

<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

5/ Load Pdf  from Java  



package com.example.pdfviewer;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.github.barteksc.pdfviewer.PDFView;

public class MainActivity extends AppCompatActivity {

PDFView pdfView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});

pdfView = findViewById(R.id.pdfView); // somossa nai eta normal error

pdfView.fromAsset("paradoxical_one.pdf").load();

}
}

Comments