Implementing Barcode Generation in Mobile Apps
Need appears unexpectedly: warehouse wants to print labels from phone, retail—generate QR checks offline, logistics—create Code128 for shipping without server. Seems minor, but wrong library choice causes problems later.
What Formats Are Actually Needed and How to Generate
Linear barcodes—EAN-13, EAN-8, UPC-A, Code128, Code39, ITF—use different check digit algorithms. Can't mix: retailers scan EAN-13, couriers—Code128 with arbitrary symbols. QR and Data Matrix cover 2D.
iOS. CIFilter natively can generate QR (CIQRCodeGenerator), Aztec, Code128, PDF417. For EAN/UPC easier to take ZXingObjC or wrapper over ZXing—covers all formats at once. Render to CIImage, scale via CGAffineTransform (no interpolation, else pixel edges blur), export to PNG via UIGraphicsImageRenderer.
Android. ZXing (com.google.zxing:core:3.5.x)—de facto standard. MultiFormatWriter.encode() returns BitMatrix, draw to Bitmap via MatrixToImageWriter or manually iterating pixels. For Jetpack Compose—wrap in AndroidView with ImageView, or use BarcodeEncoder from journeyapps/zxing-android-embedded.
Flutter. barcode_widget (pub.dev) draws via Canvas without native code. For file output—toImage() via RepaintBoundary + RenderRepaintBoundary.toImage(pixelRatio: 3.0).
Typical Pitfalls
Scaling without interpolationQuality = .none (iOS) gives blurry edges—scanner can't read. Same on Android: Bitmap.createScaledBitmap(..., true) with filtering enabled destroys Code128 sharpness at small sizes.
Contrast: black on white—not "good by default." On dark app background need explicit fgColor/bgColor. QR on transparent won't read reliably in poor lighting.
Minimum QR size with error correction level M—150×150 dp. Lower—problems on cheap Android with 8MP camera.
Dynamic Content and Batch Generation
Barcodes often generated on-the-fly from data: product SKU, order number, user ID. Template approach: String.format("ORDER-%06d", orderId) → encode → render. For batch (example: 500 labels before shipment), generate in background thread DispatchQueue.global() / Executors.newFixedThreadPool(4) and show progress.
For barcode in PDF—integrate generation with PDFKit (iOS) / android.graphics.pdf.PdfDocument (Android): draw Bitmap barcode directly on PdfDocument.Page.canvas().
Save and Share
Generate to Bitmap/UIImage, save temp file via FileProvider (Android) or UIActivityViewController (iOS). Flutter—path_provider + share_plus. On Bluetooth printer (Zebra ZPL, Citizen) send ZPL command directly, not raster image—sharp at any DPI.
Timelines
Implementation of 2–3 formats with preview and share button—1 working day. If printer integration or batch generation with templates needed—2–3 days.







