![]() |
VOOZH | about |
PDF files are used in many android applications for displaying data in the form of images, text as well as graphics. Many applications are also required to get the data from this PDF file and display this data within the android application. So for extracting the data from PDF file pdf reader is used which is used to read pdf and get the data from PDF file.
In this article, we will be building a simple application in which we will be extracting data from PDF files in Android using Jetpack Compose.
To create a new project in the Android Studio, please refer to How to Create a new Project in Android Studio with Jetpack Compose.
Navigate to Gradle Scripts > build.gradle.kts (Module :app) and add the below dependency
dependencies {
...
implementation ("com.itextpdf:itextg:5.5.10")
}
After adding this dependency simply sync your project to install it.
Refer to the following github repo to read the docs: https://github.com/itext/itextpdf
As we are extracting data from PDF files, so we will be adding PDF files to our app. To add PDF files to your app, we must create the raw folder first. Please refer to Resource Raw Folder in Android Studio to create a raw folder in android. After creating a new raw directory copy and paste your PDF file inside that βrawβ folder.
You can download a sample pdf from here.
Go to the MainActivity.kt file and refer to the following code. Comments are added inside the code to understand the code in more detail.
MainActivity.kt: