### Install PdfiumAndroidKt Core and Arrow Module Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Add the core library for synchronous and suspend APIs, and optionally the Arrow module for functional API support, to your app's build.gradle.kts file. ```kotlin implementation("io.legere:pdfiumandroid:2.0.0") implementation("io.legere:pdfium-android-kt-arrow:2.0.0") ``` -------------------------------- ### Render PDF Page to Bitmap Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Opens a specific page from a PDF document and renders it into an ARGB_8888 bitmap. It also demonstrates how to get page dimensions in pixels and points, retrieve hyperlinks, and map PDF coordinates to device coordinates. Ensure the page is opened and closed properly. ```kotlin import android.graphics.Bitmap import android.graphics.Rect import android.graphics.RectF import androidx.core.graphics.createBitmap import io.legere.pdfiumandroid.PdfiumCore import android.os.ParcelFileDescriptor import java.io.File // Assuming 'core', 'fd', 'context', 'resources', 'imageView' are available // val core = PdfiumCore(context) // val fd = ParcelFileDescriptor.open(File(context.filesDir, "report.pdf"), ParcelFileDescriptor.MODE_READ_ONLY) core.newDocument(fd).use { it.openPage(0)?.use { page -> val dpi = resources.displayMetrics.densityDpi // Pixel dimensions at screen DPI val w = page.getPageWidth(dpi) val h = page.getPageHeight(dpi) println("Page 0: ${w}x${h}px rotation=${page.getPageRotation()}") // PostScript-point dimensions println("Points: ${page.getPageWidthPoint()} x ${page.getPageHeightPoint()}") // Render to ARGB_8888 bitmap (best quality, direct write) val bitmap = createBitmap(w, h, Bitmap.Config.ARGB_8888) page.renderPageBitmap( bitmap = bitmap, startX = 0, startY = 0, drawSizeX = w, drawSizeY = h, renderAnnot = true, ) imageView.setImageBitmap(bitmap) // Extract hyperlinks val links = page.getPageLinks() links.forEach { link -> println("Link URI=${link.uri} dest=${link.destPageIdx}") } // Map a PDF-space rectangle to device pixels val mediaBox: RectF = page.getPageMediaBox() val deviceRect: Rect = page.mapRectToDevice( startX = 0, startY = 0, sizeX = w, sizeY = h, rotate = 0, coords = mediaBox.toAndroidRect(), ) println("Media box in device coords: $deviceRect") } } private fun RectF.toAndroidRect() = Rect(left.toInt(), top.toInt(), right.toInt(), bottom.toInt()) ``` -------------------------------- ### Saving PDF Document Copy with Modifications Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Demonstrates how to save a modified PDF document to a new file using `saveAsCopy` and a `PdfWriteCallback`. This example shows deleting a page before saving. ```kotlin import io.legere.pdfiumandroid.PdfDocument import io.legere.pdfiumandroid.api.PdfWriteCallback import java.io.File import java.io.FileOutputStream core.newDocument(fd).use { doc -> // Delete the first page doc.deletePage(0) val outFile = File(context.cacheDir, "modified.pdf") FileOutputStream(outFile).use { doc.saveAsCopy( callback = object : PdfWriteCallback { override fun WriteBlock(data: ByteArray): Boolean { fos.write(data) return true } }, flags = PdfDocument.FPDF_NO_INCREMENTAL, // full rewrite ) } println("Saved to ${outFile.absolutePath} (${outFile.length()} bytes)") } ``` -------------------------------- ### PdfDocument Operations Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Demonstrates how to perform operations on a PDF document, such as retrieving metadata, accessing the table of contents, getting character counts, deleting pages, and saving a modified copy. ```APIDOC ## `PdfDocument` — Document operations `PdfDocument` represents an open PDF and provides page access, metadata, bookmark enumeration, page deletion, and save-as-copy. It is `Closeable`. ```kotlin import io.legere.pdfiumandroid.PdfiumCore import io.legere.pdfiumandroid.PdfDocument import io.legere.pdfiumandroid.api.PdfWriteCallback import java.io.ByteArrayOutputStream val core = PdfiumCore(context) val fd = ParcelFileDescriptor.open(File(context.filesDir, "report.pdf"), ParcelFileDescriptor.MODE_READ_ONLY) core.newDocument(fd).use { doc: PdfDocument -> // Metadata val meta = doc.getDocumentMeta() println("Title=${meta.title} Subject=${meta.subject} Creator=${meta.creator}") // Bookmarks / table of contents val toc = doc.getTableOfContents() fun printToc(items: List, depth: Int = 0) { items.forEach { b -> println(" ".repeat(depth) + "${b.title} (page ${b.pageIdx})") printToc(b.children, depth + 1) } } printToc(toc) // Per-page character counts (fast, no page open required) val charCounts: IntArray = doc.getPageCharCounts() println("Chars per page: ${charCounts.take(5)}") // Delete last page and save copy doc.deletePage(doc.getPageCount() - 1) val out = ByteArrayOutputStream() doc.saveAsCopy(object : PdfWriteCallback { override fun WriteBlock(data: ByteArray): Boolean { out.write(data) return true } }, PdfDocument.FPDF_NO_INCREMENTAL) println("Saved ${out.size()} bytes") } ``` ``` -------------------------------- ### Configuring PdfiumCoreKt with Custom Logger and Behavior Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Illustrates how to create a Config object to customize logging and the behavior when accessing already-closed PDF objects. This allows integration with custom logging frameworks like Timber. ```kotlin import io.legere.pdfiumandroid.api.Config import io.legere.pdfiumandroid.api.AlreadyClosedBehavior import io.legere.pdfiumandroid.api.LoggerInterface import io.legere.pdfiumandroid.suspend.PdfiumCoreKt import kotlinx.coroutines.Dispatchers val config = Config( // Plug in your own logger (e.g., Timber) logger = object : LoggerInterface { override fun d(tag: String, message: String?) = Timber.tag(tag).d(message) override fun e(tag: String, t: Throwable?, message: String?) = Timber.tag(tag).e(t, message) }, // Silently log instead of throwing when a closed object is used alreadyClosedBehavior = AlreadyClosedBehavior.LOG, ) val coreKt = PdfiumCoreKt(Dispatchers.Default, config) ``` -------------------------------- ### Open PDF Document and Perform Operations Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Opens a PDF document, extracts metadata and bookmarks, retrieves character counts per page, deletes the last page, and saves the modified document as a copy. Ensure the PdfiumCore and PdfDocument are properly initialized and closed. ```kotlin import io.legere.pdfiumandroid.PdfiumCore import io.legere.pdfiumandroid.PdfDocument import io.legere.pdfiumandroid.api.PdfWriteCallback import java.io.ByteArrayOutputStream import android.os.ParcelFileDescriptor import java.io.File val core = PdfiumCore(context) val fd = ParcelFileDescriptor.open(File(context.filesDir, "report.pdf"), ParcelFileDescriptor.MODE_READ_ONLY) core.newDocument(fd).use { doc: PdfDocument -> // Metadata val meta = doc.getDocumentMeta() println("Title=${meta.title} Subject=${meta.subject} Creator=${meta.creator}") // Bookmarks / table of contents val toc = doc.getTableOfContents() fun printToc(items: List, depth: Int = 0) { items.forEach { b -> println(" ".repeat(depth) + "${b.title} (page ${b.pageIdx})") printToc(b.children, depth + 1) } } printToc(toc) // Per-page character counts (fast, no page open required) val charCounts: IntArray = doc.getPageCharCounts() println("Chars per page: ${charCounts.take(5)}") // Delete last page and save copy doc.deletePage(doc.getPageCount() - 1) val out = ByteArrayOutputStream() doc.saveAsCopy(object : PdfWriteCallback { override fun WriteBlock(data: ByteArray): Boolean { out.write(data) return true } }, PdfDocument.FPDF_NO_INCREMENTAL) println("Saved ${out.size()} bytes") } ``` -------------------------------- ### Render PDF Page with Zoom and Pan using Matrix Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Renders a PDF page to a bitmap using an affine transformation matrix for zoom and pan effects, suitable for viewer implementations. It scales the page content to fit a specified view size at a given zoom level and applies a clipping rectangle. Ensure the matrix and clipRect are correctly defined for the desired view. ```kotlin import android.graphics.Matrix import android.graphics.RectF import android.graphics.Bitmap import androidx.core.graphics.createBitmap import io.legere.pdfiumandroid.PdfiumCore import android.os.ParcelFileDescriptor import java.io.File // Assuming 'core', 'fd', 'imageView' are available // val core = PdfiumCore(context) // val fd = ParcelFileDescriptor.open(File(context.filesDir, "report.pdf"), ParcelFileDescriptor.MODE_READ_ONLY) core.newDocument(fd).use { it.openPage(0)?.use { page -> val viewWidth = 1080 val viewHeight = 1920 val zoom = 2.0f // 2× zoom val pageW = page.getPageWidthPoint().toFloat() val pageH = page.getPageHeightPoint().toFloat() val matrix = Matrix().apply { // Scale from PDF-point space to view pixels at 2× zoom setRectToRect( RectF(0f, 0f, pageW, pageH), RectF(0f, 0f, viewWidth * zoom, viewHeight * zoom), Matrix.ScaleToFit.START, ) } val clipRect = RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat()) val bitmap = createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888) page.renderPageBitmap( bitmap = bitmap, matrix = matrix, clipRect = clipRect, renderAnnot = false, ) imageView.setImageBitmap(bitmap) } } ``` -------------------------------- ### Using PdfPageKtCache for Suspend Page Caching Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Demonstrates how to use PdfPageKtCache for efficient, suspend-based caching of PDF pages within coroutines. Ensure the PdfiumCoreKt is initialized with an appropriate dispatcher. ```kotlin import io.legere.pdfiumandroid.suspend.PdfPageKtCache import io.legere.pdfiumandroid.suspend.PdfiumCoreKt import kotlinx.coroutines.Dispatchers val coreKt = PdfiumCoreKt(Dispatchers.Default) viewModelScope.launch { val doc = coreKt.newDocument(fd) data class MyHolder( val page: io.legere.pdfiumandroid.suspend.PdfPageKt, val textPage: io.legere.pdfiumandroid.suspend.PdfTextPageKt, ) : AutoCloseable { override fun close() { textPage.close(); page.close() } } val cache = PdfPageKtCache( pdfDocument = doc, dispatcher = Dispatchers.IO, ) { page, textPage -> MyHolder(page, textPage) } val holder = cache.getPage(0) val text = holder?.textPage?.textPageGetText(0, 200) println("First 200 chars: $text") cache.close() doc.close() } ``` -------------------------------- ### Open PDF Document Functionally with Arrow and PdfiumCoreKtF Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt PdfiumCoreKtF, from the Arrow module, wraps all results in Either for functional error handling. This enables error-typed pipelines without exceptions. Remember to close documents. ```kotlin import io.legere.pdfiumandroid.arrow.PdfiumCoreKtF import io.legere.pdfiumandroid.arrow.PdfiumKtFErrors import arrow.core.Either import kotlinx.coroutines.Dispatchers val coreF = PdfiumCoreKtF(dispatcher = Dispatchers.IO) viewModelScope.launch { val fd = contentResolver.openFileDescriptor(uri, "r")!! coreF.newDocument(fd) .onLeft { err: PdfiumKtFErrors -> println("Failed to open: $err") } .onRight { doc -> doc.getPageCount() .onRight { count -> println("Pages: $count") } doc.close() } } ``` -------------------------------- ### Import Prebuilt Shared Library Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/pdfiumandroid/core/src/main/cpp/CMakeLists.txt Defines an imported shared library 'libpdfium' and sets its location to a specific path within the project's JNI libraries directory, based on the Android ABI. ```cmake add_library( libpdfium SHARED IMPORTED ) set_target_properties( libpdfium PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libpdfium.so) ``` -------------------------------- ### Open PDF Document Synchronously with PdfiumCore Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Use PdfiumCore for synchronous PDF operations. It supports opening PDFs from ParcelFileDescriptor, byte arrays, and requires explicit closing of documents to release native resources. Configure behavior for already closed objects. ```kotlin import android.os.ParcelFileDescriptor import io.legere.pdfiumandroid.PdfiumCore import io.legere.pdfiumandroid.api.Config import io.legere.pdfiumandroid.api.AlreadyClosedBehavior import java.io.File val config = Config(alreadyClosedBehavior = AlreadyClosedBehavior.LOG) val core = PdfiumCore(context, config) val file = File(context.cacheDir, "sample.pdf") val fd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY) // Open without password core.newDocument(fd).use { println("Page count: ${it.getPageCount()}") // e.g. 12 val meta = it.getDocumentMeta() println("Title: ${meta.title}, Author: ${meta.author}") } // Open a password-protected PDF core.newDocument(fd, "secret").use { println("Opened protected doc with ${it.getPageCount()} pages") } // Open from byte array (e.g. downloaded over network) val bytes: ByteArray = fetchPdfBytes() core.newDocument(bytes).use { val toc: List = it.getTableOfContents() toc.forEach { bookmark -> println("Bookmark: ${bookmark.title} -> page ${bookmark.pageIdx}") } } ``` -------------------------------- ### Find NDK Libraries Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/pdfiumandroid/core/src/main/cpp/CMakeLists.txt Searches for prebuilt NDK libraries and stores their paths in variables. CMake verifies the existence of these libraries. ```cmake find_library( log-lib log) ``` ```cmake find_library( android-lib android) ``` ```cmake find_library( jnigraphics-lib jnigraphics) ``` -------------------------------- ### Implementing ByteArrayPdfiumSource for Custom Data Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Shows how to implement the PdfiumSource interface to read PDF data from a byte array. This is useful for loading PDFs from memory without writing to a temporary file. ```kotlin import io.legere.pdfiumandroid.api.PdfiumSource class ByteArrayPdfiumSource(private val data: ByteArray) : PdfiumSource { override val length: Long = data.size.toLong() override fun read(position: Long, buffer: ByteArray, size: Int): Int { val available = (length - position).coerceAtMost(size.toLong()).toInt() if (available <= 0) return 0 data.copyInto( destination = buffer, destinationOffset = 0, startIndex = position.toInt(), endIndex = position.toInt() + available, ) return available } override fun close() { /* no-op for in-memory data */ } } // Usage val pdfBytes: ByteArray = assets.open("sample.pdf").readBytes() val source = ByteArrayPdfiumSource(pdfBytes) val core = PdfiumCore(context) core.newDocument(source).use { doc -> println("Pages: ${doc.getPageCount()}") } ``` -------------------------------- ### Declare Project Name Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/pdfiumandroid/core/src/main/cpp/CMakeLists.txt Declares and names the project. This is a fundamental step in CMake configuration. ```cmake project("pdfiumandroid") ``` -------------------------------- ### PdfPage Rendering and Geometry Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Details on how to work with individual PDF pages, including rendering them to bitmaps, querying dimensions and rotation, and extracting hyperlinks. ```APIDOC ## `PdfPage` — Page rendering and geometry `PdfPage` represents a single page and exposes bitmap/surface rendering, geometry queries, coordinate mapping, and link extraction. Obtain it from `PdfDocument.openPage()`. ```kotlin import android.graphics.Bitmap import android.graphics.Rect import android.graphics.RectF import androidx.core.graphics.createBitmap core.newDocument(fd).use { doc -> doc.openPage(0)?.use { page -> val dpi = resources.displayMetrics.densityDpi // Pixel dimensions at screen DPI val w = page.getPageWidth(dpi) val h = page.getPageHeight(dpi) println("Page 0: ${w}x${h}px rotation=${page.getPageRotation()}") // PostScript-point dimensions println("Points: ${page.getPageWidthPoint()} x ${page.getPageHeightPoint()}") // Render to ARGB_8888 bitmap (best quality, direct write) val bitmap = createBitmap(w, h, Bitmap.Config.ARGB_8888) page.renderPageBitmap( bitmap = bitmap, startX = 0, startY = 0, drawSizeX = w, drawSizeY = h, renderAnnot = true, ) imageView.setImageBitmap(bitmap) // Extract hyperlinks val links = page.getPageLinks() links.forEach { link -> println("Link URI=${link.uri} dest=${link.destPageIdx}") } // Map a PDF-space rectangle to device pixels val mediaBox: RectF = page.getPageMediaBox() val deviceRect: Rect = page.mapRectToDevice( startX = 0, startY = 0, sizeX = w, sizeY = h, rotate = 0, coords = mediaBox.toAndroidRect(), ) println("Media box in device coords: $deviceRect") } } private fun RectF.toAndroidRect() = Rect(left.toInt(), top.toInt(), right.toInt(), bottom.toInt()) ``` ``` -------------------------------- ### Open PDF Document with Coroutines using PdfiumCoreKt Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt PdfiumCoreKt provides suspend functions for asynchronous PDF operations, automatically dispatching calls to a specified CoroutineDispatcher. Ensure documents are closed to release resources. ```kotlin import io.legere.pdfiumandroid.suspend.PdfiumCoreKt import io.legere.pdfiumandroid.api.Config import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext val coreKt = PdfiumCoreKt(dispatcher = Dispatchers.Default, config = Config()) viewModelScope.launch { val fd = contentResolver.openFileDescriptor(uri, "r") ?: error("Cannot open file") val document = coreKt.newDocument(fd) // suspend — runs on Dispatchers.Default try { val pageCount = document.getPageCount() // suspend println("Pages: $pageCount") } finally { document.close() } } ``` -------------------------------- ### PdfPage.renderPageBitmap with Matrix Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Advanced page rendering using an affine transformation matrix for implementing zoom and pan functionalities in a PDF viewer. ```APIDOC ## `PdfPage.renderPageBitmap` with `Matrix` (zoom / pan) Render a page using an affine transformation matrix for zooming and panning — ideal for viewer implementations. ```kotlin import android.graphics.Matrix import android.graphics.RectF import androidx.core.graphics.createBitmap core.newDocument(fd).use { doc -> doc.openPage(0)?.use { page -> val viewWidth = 1080 val viewHeight = 1920 val zoom = 2.0f // 2× zoom val pageW = page.getPageWidthPoint().toFloat() val pageH = page.getPageHeightPoint().toFloat() val matrix = Matrix().apply { // Scale from PDF-point space to view pixels at 2× zoom setRectToRect( RectF(0f, 0f, pageW, pageH), RectF(0f, 0f, viewWidth * zoom, viewHeight * zoom), Matrix.ScaleToFit.START, ) } val clipRect = RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat()) val bitmap = createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888) page.renderPageBitmap( bitmap = bitmap, matrix = matrix, clipRect = clipRect, renderAnnot = false, ) imageView.setImageBitmap(bitmap) } } ``` ``` -------------------------------- ### Add Shared Library Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/pdfiumandroid/core/src/main/cpp/CMakeLists.txt Defines a shared library named 'pdfiumandroid' and specifies its source file. Gradle automatically packages shared libraries with your APK. ```cmake add_library( pdfiumandroid SHARED pdfiumandroid.cpp) ``` -------------------------------- ### Add PdfiumAndroidKt Dependency Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/README.md Include this dependency in your app's build.gradle file to use the core PdfiumAndroidKt library. ```gradle implementation("io.legere:pdfiumandroid:2.0.0") ``` -------------------------------- ### Render PDF Page to Android Surface Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Renders a PDF page directly to an Android Surface, avoiding Bitmap allocation. Ensure the Surface is valid and the document/pages are properly managed. ```kotlin import android.view.Surface val surface: Surface = surfaceView.holder.surface core.newDocument(fd).use { doc -> val pages = doc.openPages(0, 2) // pages 0, 1, 2 try { val pageW = pages[0].getPageWidthPoint().toFloat() val pageH = pages[0].getPageHeightPoint().toFloat() val matrices = pages.mapIndexed { i, page -> Matrix().apply { setRectToRect( RectF(0f, 0f, pageW, pageH), RectF(0f, i * 1080f, 1080f, (i + 1) * 1080f), Matrix.ScaleToFit.FILL, ) } } val clips = pages.mapIndexed { i, _ -> RectF(0f, i * 1080f, 1080f, (i + 1) * 1080f) } doc.renderPages( surface = surface, pages = pages, matrices = matrices, clipRects = clips, renderAnnot = false, canvasColor = 0xFF808080.toInt(), pageBackgroundColor = 0xFFFFFFFF.toInt(), ) } finally { pages.forEach { it.close() } } } ``` -------------------------------- ### Add PdfiumAndroidKt Arrow Dependency Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/README.md Include this separate dependency if you plan to use the Arrow functional programming support module. ```gradle implementation("io.legere:pdfium-android-kt-arrow:2.0.0") ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/pdfiumandroid/core/src/main/cpp/CMakeLists.txt Specifies the minimum version of CMake required for the build. Ensure your CMake version meets this requirement. ```cmake cmake_minimum_required(VERSION 3.12...4.1.0) ``` -------------------------------- ### Link Libraries to Target Source: https://github.com/johngray1965/pdfiumandroidkt/blob/main/pdfiumandroid/core/src/main/cpp/CMakeLists.txt Specifies the libraries that CMake should link to the target library 'pdfiumandroid'. This includes custom libraries, third-party libraries, and system libraries. ```cmake target_link_libraries( pdfiumandroid libpdfium ${log-lib} ${android-lib} ${jnigraphics-lib} ) ``` -------------------------------- ### LRU PDF Page Cache Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Manages an LRU cache for PDF pages and text pages to avoid repeated open/close operations. Ensure the cache is closed when no longer needed. ```kotlin import io.legere.pdfiumandroid.PdfPageCache import io.legere.pdfiumandroid.PageHolder core.newDocument(fd).use { doc -> // Cache up to 16 pages; evicted entries are closed automatically val cache = PdfPageCache( pdfDocument = doc, maxSize = 16L, ) { page, textPage -> PageHolder(page, textPage) // built-in holder; or use a custom data class } // Access pages by index; repeated access returns the cached instance repeat(doc.getPageCount()) { i -> cache.getPage(i)?.let { holder -> val charCount = holder.textPage.textPageCountChars() println("Page $i: $charCount chars") } } cache.close() // closes all cached pages } ``` -------------------------------- ### Extract Text and Search PDF Page Source: https://context7.com/johngray1965/pdfiumandroidkt/llms.txt Utilizes PdfTextPage for character-level text access, extraction, and search within a PDF page. Ensure the page and text page are properly closed. ```kotlin core.newDocument(fd).use { doc -> doc.openPage(3)?.use { page -> page.openTextPage().use { textPage -> // Total character count val charCount = textPage.textPageCountChars() println("Characters on page 3: $charCount") // Extract all text val allText: String? = textPage.textPageGetText(0, charCount) println(allText) // Character bounding box val charBox: android.graphics.RectF? = textPage.textPageGetCharBox(10) println("Char 10 box: $charBox") // Text within a rectangular region val region = android.graphics.RectF(50f, 50f, 400f, 200f) val regionText: String? = textPage.textPageGetBoundedText(region, 512) println("Text in region: $regionText") // Font size of a character val fontSize: Double = textPage.getFontSize(0) println("Font size of char 0: $fontSize pt") // Full-text search textPage.findStart( findWhat = "invoice", flags = setOf(io.legere.pdfiumandroid.api.FindFlags.FPDF_MATCHCASE), startIndex = 0, )?.use { result -> println("First match at index ${result.getSchResultIndex()}, total ${result.getSchCount()} matches") while (result.findNext()) { println(" next match at ${result.getSchResultIndex()}") } } } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.