Android Programing _1
Adding PDF in Android Application
___________________
- Create a new Android Project
- Click on Gradle Scripts
- Click on build.gradle(Module:app) option
- Add the following lines in app
#already presented data
#copy and add only red colored data
compile 'com.android.support:appcompat-v7:23.4.0'
testCompile 'junit:junit:4.12'
compile 'com.github.barteksc:android-pdf-viewer:2.5.1'
}
- Click on "Build" Menu on MenuBar
- Click on "Rebuild Project" option (Wait for process to update)
- Click on "res"
- Click on "layout"
- Click on "activity_main.xml"
- Type the following code in activity_main.xml
com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Step-3
- Right-Click on "app"
- Goto-to "New --> Folder --> Assets Folder"
- New "assets" folder will be created on the list
- Copy the PDF in that folder by using right click paste option
- Goto "Java" --> "com.example.user......"
- Open "MainActivity" Java File
- Add the following code in that file in "onCreate" method
PDFView pdfView= (PDFView)findViewById(R.id.pdfView); pdfView.fromAsset("FPL.pdf").load();
}
}
Note: In above code "FPL.pdf" is name of pdf file copied on "assets" folder
If error found in above code while executing import the following line in import section at top of the file
import com.github.barteksc.pdfviewer.PDFView;
Run the App to Successfully access the PDF file in android app.#android #app #development #pdfinandroid
Comments