You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry maybe I am missing something but there is no documentation on any method to get the result to save to storage, like Canvas/SVG/PNG. Is this supported?
I don't know of an "official" way, but I've found a hacky way:
const base64doc = btoa(unescape(encodeURIComponent(document.getElementById('qr1').shadowRoot.querySelector('svg').outerHTML)));
const a = document.createElement('a');
const e = new MouseEvent('click');
a.download = 'download.svg';
a.href = 'data:text/html;base64,' + base64doc;
a.dispatchEvent(e);
Effectively, grab the qr-code instance, jump into its shadow root to then find the SVG that is rendering the image. From there, it's really up to you how you want to trigger a download of a file. I've included one such way. Not sure if it's the best way, but it's a way that works 😅
However, I'm not totally happy with the end result and am considering other QR code generation options at this point. But hopefully this might help someone else who stumbles upon this in the future.
Activity
denno020 commentedon Jan 22, 2024
I don't know of an "official" way, but I've found a hacky way:
Effectively, grab the
qr-codeinstance, jump into its shadow root to then find the SVG that is rendering the image. From there, it's really up to you how you want to trigger a download of a file. I've included one such way. Not sure if it's the best way, but it's a way that works 😅travisvn commentedon Jul 18, 2024
I'm using React / Next.js, and I ended up having some luck with using
html-to-imagenpm i html-to-imageAnd
However, I'm not totally happy with the end result and am considering other QR code generation options at this point. But hopefully this might help someone else who stumbles upon this in the future.
ali2b commentedon Oct 29, 2025