I want to create a QRcode (with texte or URL) and display it onthe page,
Is there a function to do that ?
Thanks for answers.
Don’t forget to tell us about your stack!
Linux debian 10
apache 2.4
Lucee 5.4.1.8
Ucanaccess 5 (driver Lucee-Access mdb through JDBC)
Hi @webonix
Do you know if your code can work in a cfdocument, to output a QR Code inside a PDF?
I’m able to output a QR code if the qr code image file is on disk, but for some reason I’m not able to use the base64 string in the img tag in a cfdocument : <img src="data:image/png;base64,#base64String#" height="600px">
Do you know if cfdocument is supposed to support this?
Thank you!
@TonyMonast. This seems to work fine on my local Lucee 5.4.6.9 install:
zxing = new com.google.zxing();
imageContentAsBase64 = zxing.createQRBinary(
content = "https://github.com/webonix/qr-code-generator/",
size = 600,
margin = 1,
fgColorHex = "25292e",
bgColorHex = "ffffff",
errorCorrection = "H"
);
html = '
<!DOCTYPE html>
<html lang="en">
<head><title>Test</title></head>
<body>
<img src="data:image/png;base64, #imageContentAsBase64#">
</body>
</html>
';
cfdocument( format="PDF", name="pdfBinary" ){
WriteOutput( Trim( html ) )
};
cfheader( name="Content-Disposition", value="attachment; filename=#Chr( 34 )#test.pdf#Chr( 34 )#" );
cfcontent( type="application/pdf", variable=pdfBinary );
2 Likes
Thank you for your answer. This allowed me to better direct my research into why it wasn’t working. Basically I don’t use quite the same library for generating the QR code and my code generates a BufferedImage instead of putting it on the disk, and I had misunderstood the nuance to recover the base64 from that. The base64 I was using for the img tag was incorrect and that’s why it wasn’t working.
Now I will do some tests to make sure that both methods are reliable in a cfdocument to refer to a qr code with the img tag : The method on disk with <img src="file:///path/to/my/qrcode.png">
or the method with the base64 <img src="data:image/png;base64,#imageContentAsBase64#">
Hi!
I used it for a project of mine.
Works perfect. Many thanks
I’ve got a little curiosity.
Why do you work with “localmode= true”?
I know what that means… I would understand why you prefer “localmode= true” to using “var” or “local” scope.
Thanks again!
1 Like