Skip to main content

Barcode Generator

The Barcode Generator is a simple tool to generate barcodes directly from the Scandit SDK. In this guide, we will show you how to use the Barcode Generator to generate barcodes and QR codes.

The Barcode Generator supports the following formats:

  • Code 39
  • Code 128
  • EAN 13
  • UPCA
  • ITF
  • QR
  • DataMatrix

Prerequisites

Before starting with adding a capture mode, make sure that you have a valid Scandit Data Capture SDK license key and that you added the necessary dependencies. If you have not done that yet, check out this guide.

note

You can retrieve your Scandit Data Capture SDK license key, by signing in to your account Dashboard.

Generating Barcodes

To generate barcodes, you need to create a SDCDataCaptureContext.

With the context you can then instantiate a SDCBarcodeGeneratorBuilder, and use the method of SDCBarcodeGenerator for the symbology you are interested in, in this example Code 128.

let context = DataCaptureContext(licenseKey: licenseKey)
let builder = BarcodeGenerator.code128BarcodeGeneratorBuilder(with: context)

You can configure the colors used in the resulting image:

builder.foregroundColor = .black
builder.backgroundColor = .white

When the builder is configured get the SDCBarcodeGenerator and try to generate the image:

do {
let generator = try builder.build()
let image = try generator.generate(with: dataString, imageWidth: 200.0)
// Use the image
} catch {
// Handle the error
print(error)
}

See the complete API reference for more information.

Generating QR Codes

To generate barcodes, you need to create a SDCDataCaptureContext.

With the context you can then instantiate a SDCQRCodeBarcodeGeneratorBuilder using the method of SDCBarcodeGenerator specific for QR codes.

let context = DataCaptureContext(licenseKey: licenseKey)
let builder = BarcodeGenerator.qrCodeBarcodeGeneratorBuilder(with: context)

You can configure the colors used in the resulting image:

builder.foregroundColor = .black
builder.backgroundColor = .white

There are two settings that can be configured for QR codes: SDCQRCodeBarcodeGeneratorBuilder.errorCorrectionLevel and SDCQRCodeBarcodeGeneratorBuilder.versionNumber.

builder.errorCorrectionLevel = .medium
builder.versionNumber = 4

When the builder is configured get the SDCBarcodeGenerator and try to generate the image:

do {
let generator = try builder.build()
let image = try generator.generate(with: dataString, imageWidth: 200.0)
// Use the image
} catch {
// Handle the error
print(error)
}

See the complete API reference for more information.