Class PassportInfo
Passport info struct containing all fields decoded from the ICAO 9303 MRZ (Machine Readable Zone) and, where available, the VIZ (Visual Inspection Zone).
MRZ fields (machine-extracted, highly reliable): DocumentType, Surname, GivenNames, PassportNumber, Country / IssuingCountryCode, Nationality / NationalityCode, DateOfBirth, Gender, DateOfExpiry, PersonalNumber.
VIZ fields (best-effort from full OCR text, may be empty): DateOfIssue.
Raw codes vs mapped names: Properties like Country and Nationality return English names mapped from ISO 3166-1 alpha-3. For custom localization, use the raw codes IssuingCountryCode and NationalityCode to perform your own mapping.
Inheritance
Implements
Namespace: IronOcr
Assembly: IronOcr.dll
Syntax
public sealed class PassportInfo : ValueType
The fields decoded from a passport, name, number, nationality, dates, and the rest, arrive in C# as a PassportInfo record. It holds everything pulled from the ICAO 9303 Machine Readable Zone (MRZ) and, where available, the Visual Inspection Zone (VIZ), so a developer reads typed properties instead of parsing the raw MRZ string by hand. It is the structured payload of a passport read, separate from the surrounding OcrPassportResult that also carries the raw Text and a Confidence score.
A PassportInfo is obtained from the PassportInfo property of an OcrPassportResult, which IronTesseract.ReadPassport returns. A developer rarely constructs one directly: the read fills it from the document, and code then reads the properties it needs. Because it is a value-type struct that implements IEquatable<PassportInfo>, two instances compare by value, and the static Empty field gives a clear "nothing decoded" sentinel to check against.
The machine-extracted MRZ fields are the reliable core: Surname, GivenNames, PassportNumber, DocumentType, Nationality, Country, and the DateOfBirth and DateOfExpiry dates. The supplementary set, DateOfIssue, IssuingCountryCode, NationalityCode, PersonalNumber, and Gender, fills in where the VIZ or extended MRZ supplies it and may be blank otherwise. The InvalidCountryCodePrefix constant marks a country value the decoder could not validate, so checking for that prefix flags a code worth a second look. Read the fields a workflow needs and validate the dates and numbers against expected formats before trusting them downstream.
using IronOcr;
var ocr = new IronTesseract();
using var input = new OcrImageInput("passport.png");
OcrPassportResult result = ocr.ReadPassport(input);
PassportInfo info = result.PassportInfo;
Console.WriteLine($"{info.Surname}, {info.GivenNames} - {info.PassportNumber}");The read passport how-to walks through MRZ extraction end to end, the passport reading example shows the decoded fields in code, and the scanned document how-to covers cleaning up a scan before the read.
Constructors
PassportInfo(String, String, String, String, String, String)
Initializes a new instance of the PassportInfo struct with the core MRZ fields.
This constructor is preserved for binary compatibility with existing compiled code.
Declaration
public PassportInfo(string surname, string givenName, string passportNumber, string country, string dateOfBirth, string dateOfExpiry)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | surname | Holder's surname. |
| System.String | givenName | Holder's given name(s). |
| System.String | passportNumber | Passport number. |
| System.String | country | Issuing state/country English name. |
| System.String | dateOfBirth | Date of birth formatted as yyyy-MM-dd. |
| System.String | dateOfExpiry | Expiry date formatted as yyyy-MM-dd. |
PassportInfo(String, String, String, String, String, String, Gender, String, String, String, String, String, String)
Initializes a new instance of the PassportInfo struct with all MRZ and VIZ decoded fields.
Declaration
public PassportInfo(string surname, string givenName, string passportNumber, string country, string dateOfBirth, string dateOfExpiry, Gender gender, string documentType, string nationality, string personalNumber, string dateOfIssue, string issuingCountryCode, string nationalityCode)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | surname | Holder's surname decoded from MRZ first row. |
| System.String | givenName | Holder's given name(s) decoded from MRZ first row. |
| System.String | passportNumber | Passport number from MRZ second row, positions 1-9. |
| System.String | country | Issuing state/country English name, mapped from MRZ first row positions 3-5. |
| System.String | dateOfBirth | Date of birth formatted as yyyy-MM-dd. |
| System.String | dateOfExpiry | Expiry date formatted as yyyy-MM-dd. |
| Gender | gender | Gender extracted from MRZ second row position 21. |
| System.String | documentType | Document type from MRZ first row positions 1-2 (e.g. "P", "PS"). |
| System.String | nationality | Holder's nationality English name, mapped from MRZ second row positions 11-13. |
| System.String | personalNumber | Optional personal/national ID number from MRZ second row positions 29-42. |
| System.String | dateOfIssue | Date of issue in yyyy-MM-dd format, extracted from VIZ (not in MRZ). |
| System.String | issuingCountryCode | Raw ISO 3166-1 alpha-3 code of the issuing state (e.g. "HRV", "USA"). |
| System.String | nationalityCode | Raw ISO 3166-1 alpha-3 code of the holder's nationality (e.g. "HRV", "USA"). |
Fields
Empty
A default empty PassportInfo with all string fields initialized to empty strings.
Declaration
public static readonly PassportInfo Empty
Field Value
| Type | Description |
|---|---|
| PassportInfo |
InvalidCountryCodePrefix
Prefix used in Country and Nationality when a country code from the MRZ could not be resolved to a known country name.
Example value: "Invalid country code (XYZ)".
Usage: if (info.Country.StartsWith(PassportInfo.InvalidCountryCodePrefix)) { ... }
Declaration
public const string InvalidCountryCodePrefix = "Invalid country code"
Field Value
| Type | Description |
|---|---|
| System.String |
Properties
Country
Issuing state/country English name, mapped from the three-letter country code (ISO 3166-1 alpha-3).
This is the country that issued the passport. For the holder's nationality, see Nationality.
For the raw ISO alpha-3 code (e.g. "HRV", "USA"), see IssuingCountryCode.
Declaration
public string Country { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
DateOfBirth
Holder's date of birth in yyyy-MM-dd format.
Returns an empty string if the date could not be parsed from the MRZ.
Declaration
public string DateOfBirth { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
DateOfExpiry
Passport expiry date in yyyy-MM-dd format.
Returns an empty string if the date could not be parsed from the MRZ.
Declaration
public string DateOfExpiry { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
DateOfIssue
Passport issue date in yyyy-MM-dd format.
Note: This field is not part of the ICAO 9303 MRZ. It is extracted on a best-effort basis from the VIZ (Visual Inspection Zone) — the human-readable printed area of the passport.
Returns an empty string if extraction was not successful.
Declaration
public string DateOfIssue { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
DocumentType
Document type indicator.
Typically "P" for a standard passport. The second character may indicate a subtype, e.g. "PD" for diplomatic passport, "PS" for service passport, or only "P" if no subtype.
Declaration
public string DocumentType { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Gender
Holder's Gender/sex.
'M' = Male, 'F' = Female, 'X' or '<' = Unspecified.
Declaration
public Gender Gender { get; }
Property Value
| Type | Description |
|---|---|
| Gender |
GivenNames
Holder's given name(s).
Multiple given names are separated by spaces.
Declaration
public string GivenNames { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
IssuingCountryCode
Raw ISO 3166-1 alpha-3 code of the issuing state (e.g. "HRV", "USA", "GBR").
Use this for custom localization or when you need the standard code rather than the English name from Country.
Declaration
public string IssuingCountryCode { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Nationality
Holder's nationality English name, mapped from the three-letter code (ISO 3166-1 alpha-3).
This may differ from Country (the issuing state) for dual citizens or diplomatic passports.
For the raw ISO alpha-3 code (e.g. "HRV", "USA"), see NationalityCode.
Declaration
public string Nationality { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
NationalityCode
Raw ISO 3166-1 alpha-3 code of the holder's nationality (e.g. "HRV", "USA", "GBR").
Use this for custom localization or when you need the standard code rather than the English name from Nationality.
Declaration
public string NationalityCode { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
PassportNumber
Unique passport number.
Declaration
public string PassportNumber { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
PersonalNumber
Optional personal number (typically a national ID number).
This field is optional per ICAO 9303. Returns an empty string if not present or filled with '<' characters.
Declaration
public string PersonalNumber { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Surname
Holder's surname (family name).
Declaration
public string Surname { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
Equals(PassportInfo)
Declaration
public bool Equals(PassportInfo others)
Parameters
| Type | Name | Description |
|---|---|---|
| PassportInfo | others |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Operators
Equality(PassportInfo, PassportInfo)
Equality operator.
Declaration
public static bool operator ==(PassportInfo left, PassportInfo right)
Parameters
| Type | Name | Description |
|---|---|---|
| PassportInfo | left | |
| PassportInfo | right |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Inequality(PassportInfo, PassportInfo)
Inequality operator.
Declaration
public static bool operator !=(PassportInfo left, PassportInfo right)
Parameters
| Type | Name | Description |
|---|---|---|
| PassportInfo | left | |
| PassportInfo | right |
Returns
| Type | Description |
|---|---|
| System.Boolean |