Your source is using 5, but Core Image is choosing 6 based on its default rules (which aren't fully documented).įinally, your source has set the error correction level to 0, which is not recommended. The second difference is the number of data columns, which drive how wide the output is. And that's also how your source is doing it. There's no way for you to configure multiple compaction methods, but you can just set it to byte, which is what value 3 is. Rather than encoding in text and then switching to bytes, or just doing it all in bytes, it switches to bytes over and over again unnecessarily. (It compacts even more if you only use uppercase Latin letters and space.) The first part of your string can be stored with text compaction, but the rest can't, so it has to switch to byte compaction.Ĭore Image actually does this switch shockingly badly by default (I opened FB9032718 to track). The default compaction mode only supports Latin text and basic punctuation.
PDF 417 defines several "compaction modes" to let it pack a truly impressive amount of information into a very small space while still offering excellent error detection and correction, and handling a lot of real-world scanning concerns. Then I'll walk through what you should probably actually do, and finally I'll get to the details of why.įirst, here's the code you're looking for (but probably not the code you want, unless you have to match this barcode): tValue(codeData, forKey: "inputMessage")įtValue(3, forKey: "inputCompactionMode") // This is good (and the big difference)įtValue(5, forKey: "inputDataColumns") // This is fine, but probably unneededįtValue(0, forKey: "inputCorrectionLevel") // This is bad
I'll start with the short answer of how to make your data match the barcode you have. Your current barcode is "correct" (though a bit messy due to an Apple bug). Choosing different parameters can lead to very different bar codes that decode identically.
Gereon is correct that there are a lot of parameters. Let imageView = UIImageView(image: image!) Let image = generatePDF417Barcode(from: keyData!) I have the following example of PDF417 barcode: