VOOZH about

URL: https://www.geeksforgeeks.org/kotlin/generate-pdf-file-in-android-using-jetpack-compose/

⇱ Generate PDF File in Android using Jetpack Compose - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Generate PDF File in Android using Jetpack Compose

Last Updated : 23 Jul, 2025

There are many apps in which data from the app is provided to users in the downloadable PDF file format. So in this case we have to create a PDF file from the data present inside our app and represent that data properly inside our app. So by using this technique we can easily create a new PDF according to our requirements.

In this article, we will take a look at creating a new PDF file from the data present within our android application using Jetpack Compose in Android. 

Steps to Generate PDF File in Android

Step 1: Create a New Project in Android Studio

To create a new project in the Android Studio, please refer to How to Create a new Project in Android Studio with Jetpack Compose.

Step 2: Adding images to the drawable folder

  • Copy the image which you want to add to your PDF file.
  • Navigate to app>res>drawable.
  • Right-click on it and paste all the images into the drawable folder.


Step 3: Adding permissions in AndroidManifest.xml

Navigate to app > manifests > AndroidManifest.xml and add the below permission to it for writing in the external storage (for until Android 9 only). 

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />


Step 4: Working with the MainActivity.kt file

Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.

MainActivity.kt:

Output:

Comment
Article Tags:

Explore