Skip to main content

How to Make a Document Scanner App

Copied to clipboard!
No boilerplate memorization required

How to Vibe Code a Native Document Scanner & PDF App

Stay in your creative flow. Direct AI models with high-level intent, stitch together perspective crop handles, B&W contrast filters, and native `PdfDocument` export in Jetpack Compose, and run your scanner APK in under 30 minutes.

Core Stack

Kotlin Compose

PDF Engine

Android PdfDocument

AI Partner

Claude / Gemini

Target Time

20–30 Mins

The Philosophy

The Vibe Coding Mobile Philosophy

Traditional document scanner development meant compiling heavy C++ OpenCV binaries, fighting Camera2 lifecycle callbacks, or paying thousands for enterprise scanner SDKs. Vibe coding uses modern Android APIs effortlessly: you describe the 4-corner crop overlay, high-contrast document filters, and native `android.graphics.pdf.PdfDocument` export while your AI assistant generates clean, self-contained Kotlin Compose code.

Old-School Mobile Stress

  • Wrestling 200MB NDK/OpenCV CMake builds just to adjust document contrast and crop corners.
  • Writing 400 lines of Camera2 boilerplate before capturing a single receipt photo.
  • Paying expensive per-seat enterprise licensing fees for basic PDF generation.
  • Struggling with Android Scoped Storage permissions when sharing a generated PDF.

The Vibe Coder Way

  • Use Compose `ColorMatrix` for instant Magic Color / B&W document enhancement with zero native C++ libraries.
  • Describe the vibe: "Microsoft Lens / CamScanner style workspace with draggable 4-corner crop handles and 1-tap PDF export."
  • Generate multi-page PDFs natively using Android's built-in `PdfDocument` class.
  • Test scanning receipts and notes on your physical phone immediately.
Execution

The 4-Step Blueprint

From an empty Compose canvas to scanning, enhancing, and exporting crisp PDFs on your handset.

Step 01

Spawning the Empty Compose Canvas

Open Android Studio and select New Project > Empty Activity (with Compose logo). Name it VibeScanner.

💡 Pro Vibe Tip: Android's built-in ActivityResultContracts.TakePicturePreview() lets you capture a camera bitmap in 5 lines of Compose code without complex CameraX setup.
Step 02

The "One-Shot Architect" Prompt

Ask your LLM for a complete single-file scanner studio: draggable 4-corner crop overlay, filter mode chips (Original, Magic Color, Crisp B&W, Grayscale), and a multi-page PDF vault.

🔑 Key Constraint: Tell the AI: "Use Android's native android.graphics.pdf.PdfDocument and ColorMatrixColorFilter so no 3rd-party dependencies are required."
Step 03

Contrast Filters & Corner Loupe

Add brightness and contrast sliders, page rotation buttons, and a clean document folder list showing page counts and timestamps.

✨ Iteration Secret: Include a built-in sample receipt canvas so you can test cropping and B&W filtering inside @Preview before opening the camera.
Step 04

Run on Your Real Phone

Pair your Android phone via Wireless Debugging, hit Run (Shift+F10), and snap a receipt or notebook page to export a tidy PDF.

🏆 The Grand Payoff: A private, watermark-free document scanner on your phone that never uploads sensitive paperwork to someone else's cloud.
Interactive Tool

Vibe Prompt Configurator

Select your scanner UI style, capture pipeline, and image enhancement tools to generate your master prompt.

Special Feature Vibe
Optional custom details added straight into your master prompt.
Generated Master Prompt
Ready to paste into Claude, Gemini, or ChatGPT Single-file Compose ready
Product Spec

Essential Elements of a Document Scanner App

To turn skewed phone photos into sharp, shareable digital documents, make sure your scanner app covers these six pillars:

  • Edge Detection & Perspective Crop

    Let users align or drag 4 corner handles around receipts, contracts, or whiteboards to flatten skewed angles into a clean rectangle.

  • Image Processing & Contrast Filters

    Provide brightness, contrast, and adaptive B&W thresholding so shadows disappear and printed text becomes razor-sharp.

  • Built-In PDF & Format Converter

    Compile single or multi-page scans into standard A4/Letter PDF files or high-resolution JPEG/PNG images ready for email or printing.

  • Scanner SDK & OCR Text Recognition

    Optionally integrate ML Kit or a scanner SDK to extract selectable, searchable text from scanned pages on the device.

  • Fast, Responsive Performance

    Process bitmaps off the main UI thread so cropping, rotating, and exporting multi-page documents feel instantaneous.

  • Intuitive Organization & Security

    Give users a clean archive to rename, tag, and share scans while keeping sensitive documents encrypted and private on the handset.

UX Checklist Before Shipping: Make the 4 crop handles large enough to drag comfortably without the user's thumb hiding the paper corner, and default to high-contrast B&W for text documents.
Starter Template

The "Golden" Single-File Compose Template

Replace the contents of your MainActivity.kt with this to test an interactive 4-corner document cropper, filter studio, and scan vault right now.

app/src/main/java/.../MainActivity.kt
Kotlin + Compose
package com.example.vibescanner

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import java.util.UUID
import kotlin.math.hypot

data class ScannedDoc(
    val id: String = UUID.randomUUID().toString(),
    val title: String,
    val filter: String,
    val contrast: Int,
    val pages: Int = 1
)

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme(
                colorScheme = darkColorScheme(
                    background = Color(0xFF090D16),
                    surface = Color(0xFF141C2B),
                    primary = Color(0xFF06B6D4)
                )
            ) {
                Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
                    VibeScannerScreen()
                }
            }
        }
    }
}

@Composable
fun VibeScannerScreen() {
    var selectedFilter by remember { mutableStateOf("Crisp B&W") }
    var contrast by remember { mutableFloatStateOf(85f) }
    var docTitle by remember { mutableStateOf("Receipt_Scan_01.pdf") }
    var savedDocs by remember {
        mutableStateOf(
            listOf(
                ScannedDoc(title = "Signed_NDA_2026.pdf", filter = "Crisp B&W", contrast = 90, pages = 3),
                ScannedDoc(title = "Coffee_Receipt.pdf", filter = "Magic Color", contrast = 80, pages = 1)
            )
        )
    }

    // Normalized 4-corner crop points
    var corners by remember {
        mutableStateOf(
            listOf(
                Offset(0.15f, 0.15f),
                Offset(0.85f, 0.12f),
                Offset(0.88f, 0.85f),
                Offset(0.12f, 0.88f)
            )
        )
    }

    val paperBg = when (selectedFilter) {
        "Crisp B&W" -> Color(0xFFF8FAFC)
        "Magic Color" -> Color(0xFFEFF6FF)
        else -> Color(0xFFCBD5E1)
    }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .statusBarsPadding()
            .padding(20.dp),
        verticalArrangement = Arrangement.spacedBy(14.dp)
    ) {
        Text("Vibe Lens & PDF 📄", fontSize = 26.sp, fontWeight = FontWeight.ExtraBold, color = Color.White)
        Text("Drag the 4 cyan corner handles to flatten perspective", fontSize = 12.sp, color = Color(0xFF94A3B8))

        // Interactive 4-Corner Crop & Filter Preview Canvas
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .height(250.dp)
                .clip(RoundedCornerShape(20.dp))
                .background(Color(0xFF141C2B))
        ) {
            Canvas(
                modifier = Modifier
                    .fillMaxSize()
                    .pointerInput(Unit) {
                        detectDragGestures { change, _ ->
                            change.consume()
                            val norm = Offset(
                                (change.position.x / size.width).coerceIn(0.05f, 0.95f),
                                (change.position.y / size.height).coerceIn(0.05f, 0.95f)
                            )
                            val nearestIdx = corners.indices.minByOrNull { idx ->
                                hypot(corners[idx].x - norm.x, corners[idx].y - norm.y)
                            } ?: 0
                            corners = corners.toMutableList().also { it[nearestIdx] = norm }
                        }
                    }
            ) {
                val pts = corners.map { Offset(it.x * size.width, it.y * size.height) }
                val path = Path().apply {
                    moveTo(pts[0].x, pts[0].y)
                    lineTo(pts[1].x, pts[1].y)
                    lineTo(pts[2].x, pts[2].y)
                    lineTo(pts[3].x, pts[3].y)
                    close()
                }
                drawPath(path = path, color = paperBg.copy(alpha = (contrast / 100f).coerceIn(0.5f, 1f)))
                drawPath(path = path, color = Color(0xFF06B6D4), style = Stroke(width = 3.dp.toPx()))
                pts.forEach { pt ->
                    drawCircle(color = Color(0xFF06B6D4), radius = 10.dp.toPx(), center = pt)
                    drawCircle(color = Color.Black, radius = 4.dp.toPx(), center = pt)
                }
            }
            Text(
                text = "$selectedFilter • ${contrast.toInt()}% Contrast",
                color = Color(0xFF0F172A),
                fontWeight = FontWeight.Bold,
                fontSize = 12.sp,
                modifier = Modifier.align(Alignment.Center)
            )
        }

        // Filter Chips
        Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
            listOf("Crisp B&W", "Magic Color", "Grayscale").forEach { mode ->
                FilterChip(
                    selected = selectedFilter == mode,
                    onClick = { selectedFilter = mode },
                    label = { Text(mode, fontSize = 12.sp) }
                )
            }
        }

        // Contrast Slider
        Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
            Text("Contrast", color = Color(0xFF94A3B8), fontSize = 13.sp)
            Slider(value = contrast, onValueChange = { contrast = it }, valueRange = 50f..100f, modifier = Modifier.weight(1f))
        }

        // Export to PDF Row
        Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
            OutlinedTextField(
                value = docTitle,
                onValueChange = { docTitle = it },
                modifier = Modifier.weight(1f),
                singleLine = true,
                label = { Text("PDF File Name", fontSize = 11.sp) }
            )
            Button(
                onClick = {
                    if (docTitle.isNotBlank()) {
                        savedDocs = listOf(
                            ScannedDoc(title = docTitle.trim(), filter = selectedFilter, contrast = contrast.toInt())
                        ) + savedDocs
                    }
                },
                shape = RoundedCornerShape(14.dp),
                modifier = Modifier.height(52.dp)
            ) {
                Text("Export PDF", color = Color.Black, fontWeight = FontWeight.Bold)
            }
        }

        // Saved PDF Vault
        LazyColumn(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {
            items(savedDocs, key = { it.id }) { doc ->
                Row(
                    modifier = Modifier
                        .fillMaxWidth()
                        .clip(RoundedCornerShape(14.dp))
                        .background(Color(0xFF141C2B))
                        .padding(14.dp),
                    horizontalArrangement = Arrangement.SpaceBetween,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Column {
                        Text(doc.title, color = Color.White, fontWeight = FontWeight.Bold, fontSize = 14.sp)
                        Text("${doc.filter} • ${doc.contrast}% contrast • ${doc.pages}p", color = Color(0xFF94A3B8), fontSize = 12.sp)
                    }
                    Text("PDF Ready", color = Color(0xFF06B6D4), fontWeight = FontWeight.Bold, fontSize = 12.sp)
                }
            }
        }
    }
}
Troubleshooting

How to Debug Without Losing Your Vibe

Avoid bitmap memory crashes and file-sharing errors with these three vibe debugging rules:

The Error Dump Rule

If sharing a PDF throws a FileUriExposedException, prompt your AI: "Save the PdfDocument to context.cacheDir and share it using FileProvider or MediaStore."

Bitmap Downsampling

12MP camera photos can exhaust heap memory. Instruct the AI: "Downsample captured camera bitmaps to max 2048px on the longest edge before applying ColorMatrix filters."

Instant Wireless Run

Pair your physical phone over Wi-Fi to test real camera capture and multi-touch corner handle dragging.

Extensions

The Vibe Prompt Vault

Copy-paste prompts to add real PDF file export, on-device OCR text extraction, and e-signatures.

📄 Prompt: Generate Real A4 PDF Files with Android PdfDocument
Prompt Template

"Add a Kotlin helper function to my Compose Document Scanner that takes a list of filtered Bitmaps, draws each onto an A4 page (595x842) using android.graphics.pdf.PdfDocument, writes the file into cacheDir, and launches Android's ACTION_SEND ShareSheet."

🔤 Prompt: Add On-Device OCR Text Extraction with ML Kit
Prompt Template

"Integrate Google ML Kit Text Recognition (com.google.mlkit:text-recognition) into my Compose Document Scanner so tapping 'Extract Text (OCR)' on any scanned page opens a bottom sheet with selectable, copyable text extracted offline."

✍️ Prompt: Add a Finger Signature Overlay Pad Onto Scanned Pages
Prompt Template

"Add a 'Sign Document' button to my Compose Document Scanner that opens a freehand signature pad dialog, captures the user's signature path, and lets them drag and scale the signature onto the scanned document before exporting to PDF."

We use cookies for ads and analytics.