Forum Discussion
Unable to generate a QR Code with base64 encoded e-invoice string
- 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!
Hi Sravan_mahindra,
Thanks for reaching out to the Microsoft Fabric Forum Community.
And aslo Thanks to SolomonovAnton for useful and prompt response.
To generate a valid e-invoice QR code in Power BI Report Builder, you must first integrate with the Invoice Registration Portal (IRP) using either a GSP/ASP service provider or your own API setup. Once an e-invoice is successfully submitted, the IRP returns a digitally signed QR code as a base64-encoded string in the SignedQRCode field of the response. This signed code is mandatory, as generating a QR code manually from raw data won't pass verification in the e-invoice scanner. In Power BI Report Builder, you need to include this SignedQRCode value in your dataset and use it to render a QR image. This is done by adding an image control, setting the source to "Database", the MIME type to "image/png", and using an expression to convert the base64 string into an image. This method ensures the QR code meets government verification standards.
If this helped, please mark the response as the accepted solution and give it a thumbs-up so others can benefit too.
Best regards,
Prasanna Kumar