0

Is it possible to generate a qr code in .net and when scanning it, it automatically downloads a pdf document instead of going to a url?

Example:

string myBase64Pdf = "base64code.....";

QRCodeGenerator _qrCode = new QRCodeGenerator();      
QRCodeData _qrCodeData = _qrCode.CreateQrCode(myBase64Pdf,QRCodeGenerator.ECCLevel.Q);  //error maximun length    
QRCode qrCode = new QRCode(_qrCodeData);      
Bitmap qrCodeImage = qrCode.GetGraphic(20);  

var htmlcontent = await repository.getTemplateHtml();
htmlcontent = htmlcontent.Replace("||QRSection||", qrCodeImage); //error but qrCodeImage must be 
string
//htmlcontent = htmlcontent.Replace("||QRSection||", qrCodeImage.ToString()); ???

var mybase64Pdf = util.ConvertHtmlToPDF(htmlcontent);

but in this line: QRCodeData _qrCodeData = _qrCode.CreateQrCode(myBase64Pdf,QRCodeGenerator.ECCLevel.Q);

I've exception:

The given payload exceeds the maximum size of the QR code standard. The maximum size allowed for the choosen paramters (ECC level=Q, EncodingMode=Byte) is 1663 byte.

Alonso Contreras
  • 605
  • 2
  • 12
  • 29
  • Point the URL to the PDF? –  Mar 11 '21 at 14:46
  • I edit post, but 've exception when pass base64 string – Alonso Contreras Mar 11 '21 at 15:05
  • 1
    Read the exception message. What you are trying to embed is too big. It looks like you're trying to embed the PDF? That won't work. –  Mar 11 '21 at 15:09
  • so i can't insert a file? must it be a url? – Alonso Contreras Mar 11 '21 at 15:48
  • 1
    https://stackoverflow.com/questions/11065415/how-much-data-information-can-we-save-store-in-a-qr-code –  Mar 11 '21 at 15:55
  • 1
    You can embed binary data in a QR code but it will probably only be readable by a program that knows what to expect. How big is your PDF file? – Lasse V. Karlsen Mar 11 '21 at 16:03
  • 1
    The problem is made worse by base64-encoding the data, making the payload ~33% bigger. –  Mar 11 '21 at 16:11
  • @Lasse V. Karlsen : the pdf size is 58.6kb but when i convert to bytes the size bytes is: 9617 – Alonso Contreras Mar 11 '21 at 16:50
  • 1
    @AlonsoContreras Once that has been base64-encoded, it will be 76kb. That is more than three times as big as what the largest QR code can handle. Even if you don't base64-encode it, it's still double the max capacity of a QR code. QR codes are not designed to send files like this. You can link to the file online, or turn your PDF into a small image, but those are the options. –  Mar 11 '21 at 16:53
  • @Amy So it is not possible to store a file inside a QR? The other solution I have is to put a url with the resource id and that the page is in charge of taking that file according to the id that I will send it. – Alonso Contreras Mar 11 '21 at 16:56
  • 1
    @AlonsoContreras The thing you are trying to put in the box is larger than the box. If you can make your PDF smaller than the box, it will fit. –  Mar 11 '21 at 16:57
  • @AlonsoContreras https://i.imgur.com/VLwJ7g9.jpg –  Mar 11 '21 at 16:59
  • @Amy hahahahah i understand!! – Alonso Contreras Mar 11 '21 at 17:01
  • Thank you all!! I will find another way to generate my qr – Alonso Contreras Mar 11 '21 at 17:02
  • The biggest binary you can put in a QR is 2953 bytes, and that is the biggest QR there is, with the lowest redundancy setting. You simply can't generate a QR to hold 9617 bytes, let alone 58.6Kb. – Lasse V. Karlsen Mar 11 '21 at 17:38

0 Answers0