ngx-qrcode icon indicating copy to clipboard operation
ngx-qrcode copied to clipboard

Download the QRcode

Open Yachos opened this issue 8 years ago • 7 comments
trafficstars

how to get the URL of the QRcode

Yachos avatar Sep 08 '17 09:09 Yachos

Any update on this? How to download a file containing the QR code?

RuiEEE avatar Nov 02 '17 20:11 RuiEEE

@RuiEEE, I'm getting the URL of the Canvas where I set my QR Code

HTML

<ngx-qrcode id="QR_Canvas" qrc-element-type="canvas" [qrc-value] =''>

TS

let something = document.querySelectorAll('canvas'), A = something as HTMLCanvasElement, somethinUrl = A.toDataURL("image/jpeg"); return somethinUrl.toString();

Yachos avatar Nov 03 '17 02:11 Yachos

@techiediaries is there any more reliable method than the canvas-fetch that @Yachos mentions? Or any chance of a property/event binding we could use to get the data URL back?

agc93 avatar Nov 20 '17 08:11 agc93

@Yachos You solution didn't work for me. The type casting gave error.

lolaswift avatar Sep 08 '18 20:09 lolaswift

@lolaswift

HTML

<ngx-qrcode qrc-element-type="canvas" [qrc-value]="YOUR_DATA"></ngx-qrcode <button ion-button (click)="getImage()">Ver imagen</button>

TS

getImage(): void { const canvas = document.querySelector("canvas") as HTMLCanvasElement; const imageData = canvas.toDataURL("image/jpeg").toString(); alert(imageData); }

Tested on Ionic 3 :)

alejandrocen avatar Nov 30 '18 19:11 alejandrocen

thats works fine, but i want to share the qr-code, what do I have to do?

MrTob avatar Jul 18 '19 18:07 MrTob

i am using this logic for downloading the QR code:-

saveQRCode() { const qrImageElement = document.getElementsByTagName("img")[0]; //as for me there is only one img tag in my view. const imageData = qrImageElement.src; //base64 data is inside the image element. const downloadLink = document.createElement("a"); downloadLink.href = imageData; downloadLink.download = this.salesUserName; downloadLink.click(); }

kishoreaoe avatar Sep 03 '22 22:09 kishoreaoe