Question: i want to create a qr code with five tlv data.

1. Sellers name
2. Vat number
3. Datetime
4. Invoice total
5. Vat amount

I need this for vat bill of Saudi arabia. I want to implement this in five steps

1. Create tlv data
2. Convert to hex representation
3. Convert to string
4. Convert to base64 string
5. Create qr code bitmap image.

Any helps will be appreciated

Answer: 
Hi We have completed and created a DEMO program to understand ( I am using c# for my demonstration)

See my Code and you should understand

1 ) Define the function to convert each TAG to hex bypassing the Tag No and TAG Value and returning the HEX Value

```
 public static String text2hex(Int32 Tagnum, String TagVal)
    {
        string hexval = text2hex(TagVal);
        string hextag = decToHexa(Tagnum);
        string hexlen = decToHexa(TagVal.Length);
        return (hextag + hexlen + hexval);
    }

```

2 ) Define a function to pass the HEX value and return a BASE64 Encoded Value

```
 public static String HexToBase64(string strInput)
    {
      var bytes = new byte[strInput.Length / 2];
            for (var i = 0; i < bytes.Length; i++)
            {
                bytes[i] = Convert.ToByte(strInput.Substring(i * 2, 2), 16);
            }
            return Convert.ToBase64String(bytes);
    }

```

3 ) convert all tags and tag values and concatenate them (TLV Format)

```
string Hexcode = text2hex(1, CompName) + text2hex(2, Vatno) + text2hex(3, datetimetax) + text2hex(4, amountTotal) + text2hex(5, amountVat);

```

4. once you have the HEXcode of the value joined convert them to base64

string HextoBase = Base64StringEncode(Hexcode)
5. Convert the Base64 to QR Code

Reference Document

[enter image description here](https://i.stack.imgur.com/rsLBW.png)
Found the issue for the Arabic. The Length for Latin text is the same in regular and utf8 mode, however for arabic, it will be different. so when producing the TLV, the L should be the length of the text after conversion to UTF8. So improving the answer above to:

```
    public static String GetTLV(Int32 Tagnum, String TagVal)
    {            
        return GetTLV(Tagnum, Encoding.UTF8.GetBytes(TagVal).Length, TagVal);
    }

    public static String GetTLV(Int32 Tagnum, int TagLen, String TagVal)
    {
        string hexval = text2hex(TagVal);
        string hextag = decToHexa(Tagnum);
        string hexlen = decToHexa(TagLen);
        return (hextag + hexlen + hexval);
    }

    private static string text2hex(string tagVal)
    {            
        byte[] ba = Encoding.UTF8.GetBytes(tagVal);
        return BitConverter.ToString(ba).Replace("-","");
    }

    private static string decToHexa(int tagnum)
    {
        return tagnum.ToString("X2").Replace("-", "");
    }        

```