Forum Discussion

Sravan_mahindra's avatar
Sravan_mahindra
New Member
1 year ago
Solved

Unable to generate a QR Code with base64 encoded e-invoice string

In Power Bi Report Builder i have to generate a QR Code using a base64 string which holds e invoice data. Successfully generated QR code using available api services ,But after scanning the QR Code ...
  • SolomonovAnton's avatar
    1 year ago

    Issue Summary

    While the API may successfully return a QR code image, it does not generate it using the required TLV-structured Base64 encoding and digital signing as mandated by e-invoice standards (e.g., ZATCA in Saudi Arabia or GSTN in India). This leads to validation failure when scanned using official apps.

    ✔️ Recommended Solution

    1. Avoid Generic QR Code APIs

    Standard QR code APIs (like Google Chart API, QRCode Monkey, etc.) only encode raw strings into QR codes and do not apply the proper TLV format or embed a valid digital signature required by the tax authorities.

    2. Generate the QR Code Manually with TLV Encoding

    You should construct the TLV string and convert it to Base64 before generating the QR code. Here's a sample in C#:

    public static string GenerateTLV(string sellerName, string vatNumber, string timestamp, string invoiceTotal, string vatTotal)
    {
        List<byte> tlvBytes = new List<byte>();
        tlvBytes.AddRange(EncodeTLV(1, sellerName));
        tlvBytes.AddRange(EncodeTLV(2, vatNumber));
        tlvBytes.AddRange(EncodeTLV(3, timestamp));
        tlvBytes.AddRange(EncodeTLV(4, invoiceTotal));
        tlvBytes.AddRange(EncodeTLV(5, vatTotal));
        return Convert.ToBase64String(tlvBytes.ToArray());
    }
    
    private static byte[] EncodeTLV(int tag, string value)
    {
        byte[] valueBytes = Encoding.UTF8.GetBytes(value);
        List<byte> tlv = new List<byte>();
        tlv.Add((byte)tag);
        tlv.Add((byte)valueBytes.Length);
        tlv.AddRange(valueBytes);
        return tlv.ToArray();
    }

    3. Render QR in Power BI Report Builder

    • Use a properly formatted Base64 string.
    • Bind it to an image control or a custom image generation service that can handle the format.

    4. Validate with Official Tools

    After implementing your own TLV + Base64 encoding logic, validate the output using the official government QR scanner (e.g., ZATCA or GSTN apps).

    5. Useful Resources

    In summary: do not rely on third-party QR code APIs for compliant e-invoice QR code generation. Use your own TLV encoding logic to meet the regulatory standards.

    ✔️ If my message helped solve your issue, please mark it as Resolved!

    👍 If it was helpful, consider giving it a Kudos!