Tools & utilities

Build a document scanner app with AI

A native document scanner build brief for snapping paper forms, cropping them cleanly and sharing a multi-page PDF from the phone.

Apirex TeamUpdated AndroidiOS
On this page
  1. Screens
  2. Data model
  3. Native features
  4. Android notes (Kotlin and Jetpack Compose)
  5. iPhone notes (Swift and SwiftUI)
  6. Copy-paste prompt
  7. Acceptance test
  8. Frequently asked questions
5screens
3data tables
195word prompt
2platforms: Android, iOS

College forms, rent agreements and signed receipts still arrive on paper, and most scanner apps wrap a simple job in ads and upsells. This brief describes a quiet scanner that photographs a page, finds its edges, saves the result as a PDF on the device and hands it to the share sheet. The best fit is iPhone, where VisionKit supplies a polished document camera; Android follows closely with the ML Kit document scanner. Building the iPhone version needs a Mac with Xcode, and every camera check has to happen on a physical phone because the iOS Simulator has no camera.

Screens

  • Scans: List saved documents with page count, date and a thumbnail of page one
  • Capture: Open the system document camera and collect one or more pages
  • Review: Reorder, rotate, recrop or delete pages before saving
  • Document detail: Rename the file, preview every page and export a PDF
  • Settings: Choose default paper size, colour mode and file naming

Data model

Document scanner records and relationships
TableKey fieldsPurpose
documentsid (uuid), title (text), created_at (timestamptz), page_count (int), pdf_path (text nullable)One scanned bundle and the location of its exported PDF
pagesid (uuid), document_id (uuid), position (int), image_path (text), rotation (int)Ordered page images that can be rearranged before export
export_settingsid (uuid), paper_size (text), color_mode (text), name_pattern (text)Preferences applied when a PDF is generated

Keep scans in app-private storage on the device by default; a scanner of personal paperwork has no reason to upload anything. If the owner later wants cloud copies, connect your own Supabase with storage policies that restrict each file path to its uploader, and make syncing an explicit per-document choice. Page images and the generated PDF are separate artifacts: editing page order should mark the PDF stale and regenerate it, not leave an older export pretending to match the current pages.

Native features

The scanner lives or dies on edge detection and a predictable export. Let the platform camera do perspective correction instead of writing a custom detector, then render the cleaned pages into a standard PDF that any messaging app can open.

FeatureAndroid (Kotlin)iPhone (SwiftUI)Notes
Page capture and auto-cropML Kit document scanner (GmsDocumentScanning) returning page imagesVisionKit VNDocumentCameraViewControllerBoth return already-cropped pages; keep the originals only if the owner asks for them.
PDF exportandroid.graphics.pdf.PdfDocument writing one page per imagePDFKit PDFDocument built from scanned UIImagesUse the chosen paper size and keep image compression readable for small print.
SharingACTION_SEND with a FileProvider content URIShareLink or UIActivityViewControllerShare the file itself, never a temporary path another app cannot read.

Android notes (Kotlin and Jetpack Compose)

Launch the ML Kit scanner with registerForActivityResult using IntentSenderRequest, and store the returned page URIs in app-private files before the activity result object goes away. Show the review screen as a LazyRow of page thumbnails keyed by page ID so drag-to-reorder animates without losing selection.

  • Save document and page rows in Room, and regenerate the PDF in a coroutine on Dispatchers.IO so a long scan never freezes the review screen. Report progress per page rather than a spinner with no end.
  • Expose exports through a FileProvider authority declared in the manifest; check that WhatsApp, Gmail and Drive all receive a readable PDF with the document title as its file name.
  • On a real Android phone, scan a crumpled three-page form under a desk lamp, rotate the device mid-review and confirm page order, rotation and the unsaved title all survive. Repeat with Google Play services updates disabled to see the fallback message when the scanner module is unavailable.

iPhone notes (Swift and SwiftUI)

Wrap VNDocumentCameraViewController in a UIViewControllerRepresentable and present it full screen from the Scans list. Persist each returned page image to the app container immediately, then create SwiftData records so a crash during review cannot drop pages the user already captured.

  • Build the PDF with PDFKit off the main actor and display it in a PDFView preview; a stale badge should appear whenever pages change after the last export.
  • Use ShareLink with a file URL whose name comes from the document title, and confirm Files, Mail and WhatsApp accept it.
  • Test on a physical iPhone: camera permission denied should show a clear path to Settings rather than a blank sheet. Scan a receipt and a full A4 page in one document, reorder them, export, and open the PDF in Files to verify both pages are upright.

Copy-paste prompt

Build this yourself 193 words · Android
Build me a scanner app for my college forms: snap the page, it auto-crops, save it as a PDF and share it to WhatsApp. No ads, nothing uploaded.
Make it a native Android app with these screens: Scans, Capture, Review, Document detail, Settings. Use the platform document camera for capture and edge cropping instead of a custom detector. Save documents and ordered pages locally with stable IDs, and generate a real PDF file on the device using the paper size I pick (ask me A4 or Letter). In Review let me reorder, rotate, delete and rescan pages; mark the PDF stale when pages change and rebuild it on export. Share the actual file through the system share sheet with the document title as the file name.
Handle camera permission denied, a cancelled scan, a scan with zero pages and low storage with clear recoverable messages. Show loading and empty states. For acceptance, scan a three-page form on a real phone, reorder two pages, export, share it to a chat app and reopen the scanner to confirm the document and its page order are still saved. List anything that still needs a device check.

Opens Apirex with this prompt in the box. Pick the Android · Kotlin tab before you send.

Acceptance test

  1. Scan a three-page paper form on a physical phone and confirm each page arrives cropped and upright in Review.
  2. Move page three to the front, rotate page two, then export and open the PDF to verify the new order and rotation.
  3. Share the PDF to a messaging app and confirm the recipient sees the document title as the file name and can open every page.
  4. Force-close the app during Review, reopen it and check that already captured pages are still present.
  5. Deny camera permission and confirm the app explains the problem and still lets you open and share existing scans.

Run one test with poor light and a page that has a coloured background. If the platform scanner fails to find edges, the user should be able to adjust the crop manually or retake the page, not receive a silently skewed export. Delete a single page from a saved document and confirm the page count, thumbnail and regenerated PDF all agree afterwards.

Frequently asked questions

Why does this need a real phone to test?

Capture relies on the device camera. The iOS Simulator has no camera at all, so VisionKit scanning can only be judged on a physical iPhone, and Android camera behaviour is most reliable on real hardware too.

Can it read the text on the page?

Text recognition is not in the first release. It can be added later with on-device ML Kit Text Recognition or the Vision framework, with search built on the recognised text.

Is anything sent to a server?

Not in this scope. Scans stay in app storage until you share them. Cloud copies only appear if you later connect your own Supabase and choose to sync a document.

Build this blueprint

The blueprint prompt, ready for your platform. Edit anything before you send it.

AndroidKotlin · Jetpack ComposeReal source on your computer

Opens Apirex with this prompt. Pick the Android · Kotlin tab before you send. The Free plan includes 5 Rex Credits a day.