{"id":19756875,"url":"https://github.com/compdfkit/compdfkit-pdf-sdk-android","last_synced_at":"2026-02-26T11:02:07.145Z","repository":{"id":47796817,"uuid":"511059751","full_name":"ComPDFKit/compdfkit-pdf-sdk-android","owner":"ComPDFKit","description":"Offer comprehensive code samples and show how to integrate the ComPDFKit PDF SDK to build a PDF viewer and editor on Android.","archived":false,"fork":false,"pushed_at":"2026-02-06T09:32:34.000Z","size":718076,"stargazers_count":39,"open_issues_count":6,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-06T17:53:47.323Z","etag":null,"topics":["android","compdfkit","java","kotlin","pdf","pdf-document","pdf-editor","pdf-viewer"],"latest_commit_sha":null,"homepage":"https://www.compdf.com/android","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ComPDFKit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-06T08:49:29.000Z","updated_at":"2026-02-06T09:32:38.000Z","dependencies_parsed_at":"2023-11-24T03:23:31.489Z","dependency_job_id":"df0fa013-4c93-4dec-8c4c-ff3736ecb6be","html_url":"https://github.com/ComPDFKit/compdfkit-pdf-sdk-android","commit_stats":null,"previous_names":["compdfkit/compdfkit-pdf-sdk-android","compdfkit/pdf-sdk-android"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/ComPDFKit/compdfkit-pdf-sdk-android","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ComPDFKit","download_url":"https://codeload.github.com/ComPDFKit/compdfkit-pdf-sdk-android/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ComPDFKit%2Fcompdfkit-pdf-sdk-android/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29856803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T08:51:08.701Z","status":"ssl_error","status_checked_at":"2026-02-26T08:50:19.607Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","compdfkit","java","kotlin","pdf","pdf-document","pdf-editor","pdf-viewer"],"created_at":"2024-11-12T03:17:18.156Z","updated_at":"2026-02-26T11:02:06.303Z","avatar_url":"https://github.com/ComPDFKit.png","language":"Java","readme":"# Introduction\n\nComPDFKit PDF SDK for Android is developed and maintained by [ComPDF](https://www.compdf.com/), enabling developers to quickly and seamlessly integrate advanced PDF functionalities—such as viewing, editing, annotating, and signing—into any Android application.\nThe ComPDFKit Android PDF Library provides an easy-to-use Java API that allows direct access to a wide range of PDF features without the need for complex configurations. By [registering for a free ComPDF API account](https://api.compdf.com/signup), developers can process up to 1,000 PDF files monthly.\nMore Information can be found at: [https://www.compdf.com/guides/pdf-sdk/android/overview](https://www.compdf.com/guides/pdf-sdk/android/overview)\n\n# Table of Content\n\n- [Related](#related)\n- [Requirements](#requirements)\n- [How to Make an Android PDF Viewer in Java](#how-to-make-an-android-pdf-viewer-in-java)\n- [Supports](#support)\n- [License](#license) \n\n\n# Related\n\n- [ComPDFKit PDF SDK for Android Documentation Guide](https://www.compdf.com/guides/pdf-sdk/android/overview)\n- [ComPDFKit PDF Library for iOS](https://github.com/ComPDFKit/compdfkit-pdf-sdk-ios-swift)\n- [How to Build an Android PDF Viewer or Editor in Java](https://www.compdf.com/blog/build-an-android-pdf-viewer-or-editor-in-java)\n- [Code Samples for Android](https://www.compdf.com/guides/pdf-sdk/android/examples) \n- [ComPDF API Reference](https://api.compdf.com/api-reference/overview)\n\n\n# Requirements\n\n[ComPDFKit Android PDF SDK](https://www.compdf.com/guides/pdf-sdk/android/overview) supports Android devices running API level 19 or newer and targets the latest stable Android 4.4 or later. In addition, it requires applications to be built with Java 8 language features enabled.\n\n- Android Studio 3.2 or newer (support AndroidX).\n- Project specifications.\n  - A `minSdkVersion` of `19` or higher.  \n  - A `compileSdkVersion` of `30` or higher.  \n  - A `targetSdkVersion` of `34` or higher.  \n  - Android ABI(s): x86, x86_64, armeabi-v7a, arm64-v8a.\n\n# How to Make an Android PDF Viewer in Java\n\nThis section will help you quickly get started with ComPDFKit PDF SDK to make an Android app in Java with step-by-step instructions. Through the following steps, you will get a simple application that can display the contents of a specified PDF file.\n\n## Video Guide:Build an Android PDF Editor in Java\n\n[![image-youtube-20250515](image-android/image-youtube-20250515.png)](https://youtu.be/SgBidb_eYjA?si=_UX7oECMc7NvC_nv)\n\n## Create a New Project\n\n1. Use Android Studio to create a Phone \u0026 Tablet project. Here we create a **No Activity** project.\n\n\u003cimg src=\"./image-android/create_project.png\" alt=\"create_project\" width=\"60%\" height=\"60%\" /\u003e\n\n\n## Installation\n\n### Integrate With Gradle\n\n1. Open the `settings.gradle` file located in your project's root directory and add the `mavenCentral` repository:\n\n```diff\ndependencyResolutionManagement {\n    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n    repositories {\n        google()\n+       mavenCentral()\n    }\n}\n```\n\n2. Open the `build.gradle` file in the application module directory:\n\n\u003cimg src=\"./image-android/2.4.2.1-1.png\" alt=\"2.4.2.1-1\" width=\"40%\" height=\"40%\" /\u003e\n\nEdit it and add the complete `ComPDFKit SDK` dependency:\n\n```groovy\ndependencies {\n  implementation 'com.compdf:compdfkit:2.6.1'\n  implementation 'com.compdf:compdfkit-ui:2.6.1'\n}\n```\n\n3. Apply for read and write permissions in `AndroidManifest.xml`:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/\u003e\n\u003cuses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/\u003e\n```\n\n**Note:** *On your apps that target Android 6.0 or higher, make sure to check for and request read and write permissions to external storage at runtime.*\n\n4. If you use an online license, please add network access permissions in `AndroidManifest.xml`:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.INTERNET\"/\u003e\n```\n\n\n### Integrate Manually\n\n1. Copy ***\"ComPDFKit.aar\"*** and ***\"ComPDFKit-UI.aar\"*** to the ***\"libs\"*** directory of the **app**.\n\n![libs.png](./image-android/libs.png)\n\n2. Add the following code into the **app** dictionary's ***\"build.gradle\"*** file:\n\n```groovy\n...\ndependencies {\n    /*ComPDFKit SDK*/\n    implementation(fileTree('libs'))\n    ...\n}\n...\n```\n\n3. Add [ComPDFKit PDF SDK for Android](https://www.compdf.com/blog/compdfkit-for-android) as a dependency to the project. Inside the **app** dictionary's ***\"build.gradle\"***, add ***\"ComPDFKit.aar\"***, ***\"ComPDFKit-UI.aar\"***, and the related support libraries to the `dependencies`. For simplicity, update the dependencies as follows:\n\n\n```groovy\ndependencies {\n    ...\n    //glide\n    implementation 'com.github.bumptech.glide:glide:4.12.0'\n    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'\n\n    implementation 'androidx.documentfile:documentfile:1.0.1'\n}\n```\n\n4. Apply for read and write permissions in `AndroidManifest.xml`:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/\u003e\n\u003cuses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/\u003e\n```\n\n**Note:** *On your apps that target Android 6.0 or higher, make sure to check for and request read and write permissions to external storage at runtime.*\n\n5. If you use an online license, please add network access permissions in `AndroidManifest.xml`:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.INTERNET\"/\u003e\n```\n\n\n\n## Apply the License Key\n\n\nAdd this license in the **AndroidManifest.xml** of the main module. In version **1.13.0**, we introduced a brand-new online authentication license scheme for ComPDFKit SDK. By default, the SDK performs online authentication. If you are using a version prior to **1.13.0**, please refer to the following example to configure the SDK for offline authentication mode:\u003cbr/\u003e\n\n* **Online license**\n\n```xml\n\u003c!-- Each ComPDFKit license is bound to a specific applicationId --\u003e\n\u003c!-- For example: com.compdfkit.pdfviewer --\u003e\n\u003cmeta-data\n    android:name=\"compdfkit_key_online\"\n    android:value=\"Your ComPDFKit Key\" /\u003e\n```\n\nYou can also initialize ComPDFKit SDK in code using:\n\n```java\nCPDFSdk.init(context, \"your compdfkit license\", false);\n```\n\n* **Offline license**\n\n```xml\n\u003c!-- Each ComPDFKit license is bound to a specific applicationId --\u003e\n\u003c!-- For example: com.compdfkit.pdfviewer --\u003e\n\u003cmeta-data\n    android:name=\"compdfkit_key\"\n    android:value=\"Your ComPDFKit Key\" /\u003e\n```\n\nYou can also initialize ComPDFKit SDK in code using:\n\n```java\nCPDFSdk.init(context, \"your compdfkit license\");\n```\n\n\n\n## Add Proguard Rules\n\nIn the `proguard-rules.pro` file, please add the obfuscation configuration information for `compdfkit` as follows:\n\n```\n-keep class com.compdfkit.ui.** {*;}\n-keep class com.compdfkit.core.** {*;}\n```\n\n\n\n## Display a PDF Document\n\n1. Copy a PDF document into the **assets** directory of your Android project. For example, import the file ***\"Quick Start Guide.pdf\"*** to the path **src/main/assets**.\n\n\n![structure.png](./image-android/structure.png)\n\n2. Create a new **Empty Activity** under your package, and set the activity name to **MainActivity**.\n\n\n\u003cimg src=\"./image-android/new_activity.png\" alt=\"new_activity\" width=\"40%\" height=\"40%\" /\u003e\n\nAndroid Studio will automatically generate a source file called ***\"MainActivity.java\"*** and a layout file called ***\"activity_main.xml\"***.\n\nThe source file:\n\n![activity_java.png](./image-android/activity_java.png)\n\nThe layout file:\n\n![layout.png](./image-android/layout.png)\n\n3. Create a `CPDFReaderView` in your ***\"activity_main.xml\"*** to display the contents of the PDF document:\n\n```xml\n\u003c!-- Your activity_main.xml file --\u003e\n\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003candroidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    tools:context=\".MainActivity\"\u003e\n\n    \u003c!-- Create a CPDFReaderView --\u003e\n    \u003ccom.compdfkit.ui.reader.CPDFReaderView\n        android:id=\"@+id/readerview\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\" /\u003e\n\n\u003c/androidx.constraintlayout.widget.ConstraintLayout\u003e\n```\n\nGet the `CPDFReaderView` from the layout or create a `CPDFReaderView` directly in the code in the corresponding ***MainActivity.java*** file:\n\n```Java\n// Your MainActivity.java file\n\npackage com.compdfkit.pdfviewer;\n\nimport androidx.appcompat.app.AppCompatActivity;\n\nimport android.os.Bundle;\nimport com.compdfkit.ui.reader.CPDFReaderView;\n\npublic class MainActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        // Get CPDFReaderView from xml.\n        CPDFReaderView readerView = findViewById(R.id.readerview);\n        // Code to create CPDFReaderView.\n        // CPDFDocument readerView = new CPDFReaderView(content);\n    }\n}\n```\n4. Open the document. This is a time-consuming process, so it needs to be executed in a **sub-thread**. After the document is opened successfully, the UI that renders the PDF is initiated:\n\n```Java\n// Your MainActivity.java file\n\n... //imports\n\npublic class MainActivity extends AppCompatActivity {\n\n    // Copy the PDF file from the assets folder to the cache folder.\n    private void copyPdfFromAssetsToCache(String fileName) {\n        try {\n            InputStream inputStream = getAssets().open(fileName);\n            File outputFile = new File(getCacheDir(), fileName);\n            FileOutputStream outputStream = new FileOutputStream(outputFile);\n\n            byte[] buffer = new byte[1024];\n            int bytesRead;\n            while ((bytesRead = inputStream.read(buffer)) != -1) {\n                outputStream.write(buffer, 0, bytesRead);\n            }\n\n            inputStream.close();\n            outputStream.flush();\n            outputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n    \n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        CPDFReaderView readerView = findViewById(R.id.readerview);\n        // Code to create CPDFReaderView.\n        // CPDFDocument readerView = new CPDFReaderView(content);\n\n        //Create a document object.\n        CPDFDocument document = new CPDFDocument(this);\n        \n\n        new Thread(() -\u003e {\n            String fileName = \"Quick Start Guide.pdf\";\n            copyPdfFromAssetsToCache(fileName);\n\n            File file = new File(getCacheDir(), fileName);\n            String filePath = file.getAbsolutePath();\n\n            //Open document.\n            CPDFDocument.PDFDocumentError error = document.open(filePath);\n            if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword) {\n                //The document is encrypted and requires a password to open.\n                error = document.open(filePath, \"password\");\n            }\n\n            if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {\n                //The document is opened successfully and data can be parsed and manipulated.\n            } else {\n                //The PDF file failed to open. You can refer to the API file for specific error\n            }\n        }).start();\n    }\n}\n```\n\n5. Set the basic properties of `CPDFReaderView` :\n\n```Java\n// Your MainActivity.java file\n\n... // imports\n\npublic class MainActivity extends AppCompatActivity {\n    // Create a handler to run the code on the main thread.\n    private Handler mainThreadHandler = new Handler(Looper.getMainLooper());\n...\n    if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {\n        // The document is opened successfully and data can be parsed and manipulated.\n        mainThreadHandler.post(() -\u003e {\n            // Set the document content for UI.\n            readerView.setPDFDocument(document);\n        });\n    } else {\n        // The PDF file failed to open. You can refer to the API file for specific error\n    }\n...\n}\n```\n\n6. Your code may resemble the following at this stage: \n\n```Java\n// Your MainActivity.java file\n\n... // imports\n\npublic class MainActivity extends AppCompatActivity {\n    // Create a handler to run the code on the main thread.\n    private Handler mainThreadHandler = new Handler(Looper.getMainLooper());\n    // Copy the PDF file from the assets folder to the cache folder.\n    private void copyPdfFromAssetsToCache(String fileName) {\n        try {\n            InputStream inputStream = getAssets().open(fileName);\n            File outputFile = new File(getCacheDir(), fileName);\n            FileOutputStream outputStream = new FileOutputStream(outputFile);\n\n            byte[] buffer = new byte[1024];\n            int bytesRead;\n            while ((bytesRead = inputStream.read(buffer)) != -1) {\n                outputStream.write(buffer, 0, bytesRead);\n            }\n\n            inputStream.close();\n            outputStream.flush();\n            outputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        CPDFReaderView readerView = findViewById(R.id.readerview);\n\n        //Create a document object.\n        CPDFDocument document = new CPDFDocument(this);\n\n        new Thread(() -\u003e {\n            String fileName = \"Quick Start Guide.pdf\";\n            copyPdfFromAssetsToCache(fileName);\n\n            File file = new File(getCacheDir(), fileName);\n            String filePath = file.getAbsolutePath();\n\n            //Open document.\n            CPDFDocument.PDFDocumentError error = document.open(filePath);\n            if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword) {\n                //The document is encrypted and requires a password to open.\n                error = document.open(filePath, \"password\");\n            }\n\n            if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {\n                //The document is opened successfully and data can be parsed and manipulated.\n                mainThreadHandler.post(() -\u003e {\n                    //Set the document to the reader view.\n                    readerView.setPDFDocument(document);\n                });\n            } else {\n                //The PDF file failed to open. You can refer to the API file for specific error\n            }\n        }).start();\n    }\n}\n```\n\n```xml\n\u003c!-- Your activity_main.xml file --\u003e\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003candroidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    tools:context=\".MainActivity\"\u003e\n\n    \u003ccom.compdfkit.ui.reader.CPDFReaderView\n        android:id=\"@+id/readerview\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\" /\u003e\n\n\u003c/androidx.constraintlayout.widget.ConstraintLayout\u003e\n```\n\n7. Run the application.\n\n\u003cimg src=\"./image-android/screen_shot.png\" alt=\"screen_shot.png\" width=\"25%\" height=\"25%\" /\u003e\n\nNow, with the help of ComPDFKit, you can get a simple application to display a PDF file.\n\n# Support\n\nComPDF offers professional technical support and 5*24 responsive service.\n\n- For detailed information, please visit our [Guides](https://www.compdf.com/guides/pdf-sdk/android/overview) page.\n\n- Stay updated with the latest improvements through our [Changelog](https://www.compdf.com/pdf-sdk/changelog-android).\n\n- For technical assistance, please reach out to our [Technical Support](https://www.compdf.com/support).\n\n- To get more details and an accurate quote, please contact our [Sales Team](https://compdf.com/contact-us) or [Send an Email](mailto:support@compdf.com) to us.\n\n\n\n\n# License\n\nComPDF offers developers a [30-day free trial license](https://www.compdf.com/pricing) for free testing your Android projects. Additionally, you'll have access to a fully-featured product with no limitations on file or user count. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompdfkit%2Fcompdfkit-pdf-sdk-android/lists"}