Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.
Rust androiddocument-scannerdocximage-editorjetpack-composekotlinliquid-glassofflineopen-sourcepdfpdf-compressorpdf-editorpdf-mergerpdf-readerpdf-splitterpdf-toolspdf-viewerpptxspreadsheet-editorxlsx
Fix OOM crash opening very large PDFs; add Obtainium install, fix stale version in README
chethan6166d1765a222a1
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt b/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.ktindex f62cf00..32f7054 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt@@ -287,6 +287,10 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModel// gives that race a head start.private const val PREFETCH_AHEAD = 2private const val PREFETCH_BEHIND = 1+ // Above this, the on-open form/link scan is skipped outright rather than risking PDFBox's+ // temp-file-backed load on a huge document for a feature (form fields, in-document links)+ // that scanned books essentially never have.+ private const val FORM_SCAN_SIZE_LIMIT_BYTES = 150L * 1024 * 1024}fun openPdf(context: Context, uri: Uri, password: String? = null) {@@ -394,14 +398,24 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModelrenderedByOfficeEngine = renderedUri.path?.contains("/office-pdf/") == true)// Fillable fields and links, read off the main thread in one pass; most PDFs have- // no form and stay empty.+ // no form and stay empty. This used to load the whole file into PDFBox's in-memory+ // model unconditionally on every open — a multi-hundred-MB scanned book (all image+ // XObjects, no forms) OOM'd right after opening, before the user did anything. Above+ // FORM_SCAN_SIZE_LIMIT_BYTES skip the scan (forms/links are rare in huge scans and+ // not worth the risk); below it, load through a temp-file-backed buffer instead of+ // the heap.val formDocUri = doc.uriviewModelScope.launch {val (widgets, links) = withContext(Dispatchers.IO) {- runCatching {+ if (doc.sizeBytes > FORM_SCAN_SIZE_LIMIT_BYTES) {+ emptyMap<Int, List<com.kyant.pdfcore.form.PdfFormWidget>>() to emptyMap()+ } else runCatching {com.kyant.pdfcore.internal.PdfBox.ensureInitialized(context)context.contentResolver.openInputStream(formDocUri)?.use { input ->- com.tom_roush.pdfbox.pdmodel.PDDocument.load(input).use { pd ->+ com.tom_roush.pdfbox.pdmodel.PDDocument.load(+ input,+ com.tom_roush.pdfbox.io.MemoryUsageSetting.setupTempFileOnly()+ ).use { pd ->val w = runCatching { com.kyant.pdfcore.form.PdfFormWidgets.read(pd) }.getOrDefault(emptyMap())val l = runCatching { com.kyant.pdfcore.link.PdfLinks.read(pd) }.getOrDefault(emptyMap())w to ldiff --git a/readme.md b/readme.mdindex dd1fe7b..ed2b837 100644--- a/readme.md+++ b/readme.md@@ -8,6 +8,7 @@ Read and annotate PDFs, sign forms, work with Office documents, edit spreadsheet<p><a href="https://github.com/Chethan616/ClearPDF/releases/latest"><strong>Download the latest ClearPDF</strong></a>+ · <a href="https://apps.obtainium.imranr.dev/redirect?r=https://github.com/Chethan616/ClearPDF"><strong>Add to Obtainium</strong></a>· <a href="https://github.com/Chethan616/ClearPDF/releases">All releases</a>· <a href="https://github.com/Chethan616/ClearPDF/issues/new/choose">Report a problem or request a feature</a>· <a href="CONTRIBUTING.md">Contribute</a>@@ -20,6 +21,8 @@ Read and annotate PDFs, sign forms, work with Office documents, edit spreadsheet<a href="LICENSE"><img src="https://img.shields.io/github/license/Chethan616/ClearPDF?style=flat-square&color=30D158" alt="MIT license"></a><img src="https://img.shields.io/badge/Android-6.0%2B-3DDC84?style=flat-square&logo=android&logoColor=white" alt="Android 6.0 or newer"><a href="https://github.com/Chethan616/ClearPDF/actions/workflows/android.yml"><img src="https://img.shields.io/github/actions/workflow/status/Chethan616/ClearPDF/android.yml?branch=main&style=flat-square&label=Android%20build" alt="Android build status"></a>+ <a href="https://apps.obtainium.imranr.dev/redirect?r=https://github.com/Chethan616/ClearPDF"><img src="https://img.shields.io/badge/Obtainium-Add%20repo-1B5E20?style=flat-square" alt="Add to Obtainium"></a>+ <img src="https://img.shields.io/badge/GitHub%20Trending-%232-FF375F?style=flat-square" alt="Number 2 on GitHub Trending"></p></div>@@ -91,7 +94,7 @@ ClearPDF annotates PDFs and edits form fields, signatures, and pages, but it doe## Download-The current stable release is **V4 (app version 2.0.0)**. Open the [V4 release page](https://github.com/Chethan616/ClearPDF/releases/tag/v4) and choose the APK that matches your device:+The current stable release is **V5.1 (app version 2.1.1)**. Open the [latest release page](https://github.com/Chethan616/ClearPDF/releases/latest) and choose the APK that matches your device:| APK suffix | Choose it for ||---|---|@@ -100,7 +103,15 @@ The current stable release is **V4 (app version 2.0.0)**. Open the [V4 release p| <code>-x86_64.apk</code> or <code>-x86.apk</code> | x86-based emulators and devices || <code>-universal.apk</code> | A larger package containing the release's supported ABIs |-The GitHub APKs are the FOSS distribution. The optional Office engine is downloaded only when requested in Settings. For future builds, use the [latest release page](https://github.com/Chethan616/ClearPDF/releases/latest). You can also add the repository to [Obtainium](https://github.com/ImranR98/Obtainium) for release update notifications.+The GitHub APKs are the FOSS distribution. The optional Office engine is downloaded only when requested in Settings.++### Install via Obtainium++[Obtainium](https://github.com/ImranR98/Obtainium) tracks this repository's releases and installs/updates the APK for you, no manual downloads.++1. Open Obtainium → **Add App**.+2. Paste `https://github.com/Chethan616/ClearPDF`, or tap **[Add to Obtainium](https://apps.obtainium.imranr.dev/redirect?r=https://github.com/Chethan616/ClearPDF)** on a device with Obtainium installed.+3. Pick the APK suffix for your device from the table above when prompted.## Privacy and network use