Generate QR Code and get base64 without displaying on page
mdodge-ecgrow opened this issue · comments
I'm wondering if there is a way to generate the QR Code in js code and get the base64 without displaying it on the page.
I figured out how to get the base64 from an existing QR code on the page with the following:
const qrCodeCanvas = document.querySelector('canvas');
const qrCodeDataUri = qrCodeCanvas.toDataURL('image/jpg', 0.1);
setQRCodeString(qrCodeDataUri);
But then I have to hide the qr code with css, and it seems very inefficient. Plus I need to be able to generate multiple different QR code base64 strings. The reason I need the base64 strings is to display them in a PDF using react-pdf (https://react-pdf.org/). Supposedly that pdf library supports SVG, but I couldn't get it to work.
If rendering and hiding is inefficient, then you probably don't want to use a library which renders. Maybe consider generating the base64 encoded strings with some other library or server side.