这是我用来解码PDF417
.Swift
private let pdf417Map: [String: String] = [
"DAA":"Full Name",
"DAB":"Family Name",
"DAC":"Given Name",
"DAD":"Middle Name",
"DAE":"Name Suffix",
"DAF":"Name Prefix",
"DAG":"Mailing Street Address1",
"DAH":"Mailing Street Address2",
"DAI":"Mailing City",
"DAJ":"Mailing Jurisdiction Code",
"DAK":"Mailing Postal Code",
"DAL":"Residence Street Address1",
"DAM":"Residence Street Address2",
"DAN":"Residence City",
"DAO":"Residence Jurisdiction Code",
"DAP":"Residence Postal Code",
"DAQ":"License or ID Number",
"DAR":"License Classification Code",
"DAS":"License Restriction Code",
"DAT":"License Endorsements Code",
"DAU":"Height in FT_IN",
"DAV":"Height in CM",
"DAW":"Weight in LBS",
"DAX":"Weight in KG",
"DAY":"Eye Color",
"DAZ":"Hair Color",
"DBA":"License Expiration Date",
"DBB":"Date of Birth",
"DBC":"Sex",
"DBD":"License or ID Document Issue Date",
"DBE":"Issue Timestamp",
"DBF":"Number of Duplicates",
"DBG":"Medical Indicator Codes",
"DBH":"Organ Donor",
"DBI":"Non-Resident Indicator",
"DBJ":"Unique Customer Identifier",
"DBK":"Social Security Number",
"DBL":"Date Of Birth",
"DBM":"Social Security Number",
"DBN":"Full Name",
"DBO":"Family Name",
"DBP":"Given Name",
"DBQ":"Middle Name or Initial",
"DBR":"Suffix",
"DBS":"Prefix",
"DCA":"Virginia Specific Class",
"DCB":"Virginia Specific Restrictions",
"DCD":"Virginia Specific Endorsements",
"DCE":"Physical Description Weight Range",
"DCF":"Document Discriminator",
"DCG":"Country territory of issuance",
"DCH":"Federal Commercial Vehicle Codes",
"DCI":"Place of birth",
"DCJ":"Audit information",
"DCK":"Inventory Control Number",
"DCL":"Race Ethnicity",
"DCM":"Standard vehicle classification",
"DCN":"Standard endorsement code",
"DCO":"Standard restriction code",
"DCP":"Jurisdiction specific vehicle classification description",
"DCQ":"Jurisdiction-specific",
"DCR":"Jurisdiction specific restriction code description",
"DCS":"Last Name",
"DCT":"First Name",
"DCU":"Suffix",
"DDA":"Compliance Type",
"DDB":"Card Revision Date",
"DDC":"HazMat Endorsement Expiry Date",
"DDD":"Limited Duration Document Indicator",
"DDE":"Family Name Truncation",
"DDF":"First Names Truncation",
"DDG":"Middle Names Truncation",
"DDH":"Under 18 Until",
"DDI":"Under 19 Until",
"DDJ":"Under 21 Until",
"DDK":"Organ Donor Indicator",
"DDL":"Veteran Indicator",
"PAA":"Permit Classification Code",
"PAB":"Permit Expiration Date",
"PAC":"Permit Identifier",
"PAD":"Permit IssueDate",
"PAE":"Permit Restriction Code",
"PAF":"Permit Endorsement Code",
"ZVA":"Court Restriction Code"
]
// metadataObj = @ ANSI 63601404....
if metadataObj.stringValue != nil {
let licenseData = metadataObj.stringValue!.components(separatedBy: "\n")
var customerProfile: [[String: String]] = []
for item in licenseData {
var metaDataItem = item
if metaDataItem.count > 3 {
if let dlCodeRange = metaDataItem.range(of: "DAQ") {
let dlStart = dlCodeRange.lowerBound
let dlEnd = metaDataItem.index(metaDataItem.endIndex, offsetBy: 0)
let dlNoRange = dlStart..<dlEnd
metaDataItem = String(metaDataItem[dlNoRange])
}
// Get the 3 letter code
let pdf417Code = String(metaDataItem.prefix(3))
// See if the code exists in the map
if pdf417Map[pdf417Code] != nil {
// Code exists in map, save to profile
let start = metaDataItem.index(metaDataItem.startIndex, offsetBy: 3)
let end = metaDataItem.index(metaDataItem.endIndex, offsetBy: 0)
let range = start..<end
let extractedData = metaDataItem[range]
customerProfile.append([pdf417Map[pdf417Code]!: String(extractedData)])
}
}
}
print("customerProfile: \(customerProfile)")
}