Implementing Document Annotation in Mobile Applications
A PDF editor on mobile isn't just drawing over an image. Annotations must embed into the PDF file structure, scale without losing position when zooming, and save so that Adobe Acrobat can read them. This is where most implementations fail.
Annotation Types and Technical Implementation
PDF 1.7 standard (ISO 32000) defines annotation types: /Text (sticky note), /Highlight, /Underline, /StrikeOut, /Ink (freehand drawing), /FreeText, /Square, /Circle, /Stamp. Implementing them as an overlay over UIImageView is an antipattern: on page re-render, positions drift. Annotations must store in PDF coordinate space (PDF points, not screen pixels).
iOS. PDFKit (available since iOS 11)—native framework with PDFAnnotation. Create annotation:
let annotation = PDFAnnotation(bounds: bounds, forType: .highlight, withProperties: nil)
annotation.color = UIColor.yellow.withAlphaComponent(0.5)
page.addAnnotation(annotation)
Coordinates in bounds are in the PDF page coordinate space. Converting from touch coordinates: pdfView.convert(touchPoint, to: page). For Ink annotation, collect [UIBezierPath] and pass via annotation.paths. Saving: document.write(to: url)—embeds annotations into the PDF structure.
Android. No native PDF editor. Common approaches: PdfiumAndroid for rendering + custom Canvas overlay with saving via iText7 or PDFBox. iText7 (Community, AGPL) can add annotations to existing PDF via PdfAnnotation. Commercial option—PdfTron/Apryse SDK: full ISO 32000 standard, offline capable.
Flutter. syncfusion_flutter_pdfviewer + syncfusion_flutter_pdf (commercial for production) or pdfx for rendering + manual implementation via CustomPainter. No free complete solution—either paid SDK or native plugin.
The Hardest Part: Ink Annotations and Stylus
Freehand drawing with finger works fine. Stylus (Apple Pencil, Samsung S Pen) is different.
On iOS, Apple Pencil provides UITouch.force and UITouch.azimuthAngle. For realistic drawing: vary line width by pressure, apply smoothing via Catmull-Rom spline between points. Without smoothing, fast strokes look jagged—UITouch doesn't capture all intermediate points.
Rendering optimization: don't redraw the entire page on each touchesMoved. Use setNeedsDisplayInRect with bounding box of the last segment. On complex documents, full redraw drops FPS to 20–30; incremental maintains 60.
Text Highlighting (Highlight) Over PDF
Correct highlighting requires knowing word coordinates in the PDF. PDFPage.selectionForRange and PDFSelection provide PDFPage.characterBounds(at:) for each character. Draw highlight not as a single rectangle for the entire selection, but as a set of rectangles per line—otherwise multiline selections appear as one wide block instead of neat strips.
Export and Compatibility
After editing, users expect a PDF that opens in any reader. PDFKit.document.write(to:) on iOS guarantees this. On Android, iText7 writes standard annotations. Issues arise with custom stamps and SVG images—these need rasterization before embedding.
Sharing: UIActivityViewController on iOS, FileProvider + Intent.ACTION_SEND on Android.
Timeline
Basic annotation set (highlight, underline, freetext, ink) on one platform—3–4 days. Full editor with stylus support, device synchronization, and cloud storage—2–3 weeks.







