This project provides:
-
📖 PDF Rendering
-
🔍 Text Search inside PDF
-
✨ Highlight Search Results
-
⬆⬇ Navigate Between Results
-
🔎 Pinch to Zoom
-
↔ Horizontal Pan
-
📜 Smooth Vertical Scroll
-
⚡ Background Rendering using Coroutines
Step 1: Add JitPack repository to your root build.gradle:
maven { url = uri("https://jitpack.io") }Step 2: Add the dependency in your app build.gradle (example if hosted on JitPack):
dependencies {
implementation 'com.github.Excelsior-Technologies-Community:Android_PdfSearchText:1.0.0'
}<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="PdfSearchLib">
<attr name="pdfSearch_barBackground" format="color"/>
<attr name="pdfSearch_barIconTint" format="color"/>
<attr name="pdfSearch_searchBoxBg" format="color"/>
<attr name="pdfSearch_searchTextColor" format="color"/>
<attr name="pdfSearch_searchHintColor" format="color"/>
<attr name="pdfSearch_countTextColor" format="color"/>
<attr name="pdfSearch_pageBg" format="color"/>
<attr name="pdfSearch_emptyTextColor" format="color"/>
<attr name="pdfSearch_btnPrevColor" format="color"/>
<attr name="pdfSearch_btnNextColor" format="color"/>
</declare-styleable>
</resources>
- Add in XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:gravity="center" android:padding="32dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="PDF Search Demo" android:textSize="22sp" android:textStyle="bold"
android:textColor="#1565C0" android:layout_marginBottom="32dp"/>
<Button android:id="@+id/btnPickOwn"
android:layout_width="match_parent" android:layout_height="52dp"
android:text="Pick PDF myself, then open viewer"
android:textAllCaps="false" android:backgroundTint="#0D47A1"/>
</LinearLayout>
package com.ext.android_pdfsearchtext
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.ext.android_pdf_search_text.PdfSearchLib
class MainActivity : AppCompatActivity() {
private val RC_PICK = 1001
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// You pick the file, library opens it directly — ONE LINE
findViewById<Button>(R.id.btnPickOwn).setOnClickListener {
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
type = "application/pdf"
addCategory(Intent.CATEGORY_OPENABLE)
}
startActivityForResult(Intent.createChooser(intent, "Select PDF"), RC_PICK)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_PICK && resultCode == Activity.RESULT_OK) {
val uri: Uri = data?.data ?: return
PdfSearchLib.start(
context = this,
uri = uri,
barBg = 0xFFC62828.toInt(),
barIcon = 0xFFFFFFFF.toInt(),
searchBoxBg = 0xFFFFFFFF.toInt(),
searchText = 0xFF212121.toInt(),
searchHint = 0xFFEF9A9A.toInt(),
countText = 0xFFC62828.toInt(),
pageBg = 0xFFFFEBEE.toInt(),
emptyText = 0xFFE57373.toInt(),
btnPrev = 0xFFFFFFFF.toInt(),
btnNext = 0xFFFFFFFF.toInt()
)
}}}
MIT License
Copyright (c) 2025 Excelsior Technologies
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED **"AS IS"**, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
