Skip to main content
Inspiring
November 8, 2019
Question

QR Code in a PDF

  • November 8, 2019
  • 1 reply
  • 1382 views

I am trying to generate a pdf using cfhtmltopdf with a QR code in it. My code displays the QR code without the cfhtmltopdf tag however when I add the tag the page is blank. I am using the jquery from https://www.jqueryscript.net/other/Canvas-Table-QR-Code-Generator.html to create the QR code.  I have tried copying all the actual scripts into the tag instead of links and that didn't help.

 

Looking for a solution - I'm open to a different method of generating the QR code if that works. 

 

Thanks in advance...

 

<cfhtmltopdf>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

<script type="text/javascript" src="../src/jquery.qrcode.js"></script>
<script type="text/javascript" src="../src/qrcode.js"></script>

<div id="qrcodeCanvas"></div>
<script>
	$('#qrcodeCanvas').qrcode({
		text	: "https://google.com"
	});
</script>
</cfhtmltopdf>

 

This topic has been closed for replies.

1 reply

ghanna1Author
Inspiring
November 8, 2019

I just found this code here: https://github.com/mohokh67/ColdFusion-QR-code-in-PDF

I get "Could not find the CF component or interface qrJavaLoader.JavaLoader" when I try to use the code. I have 0 experience working with cfc files and javaloader. Any direction on where to put these files etc. would be appreciated. 

<cfset paths = arrayNew(1)>
<cfset paths[1] = expandPath("qrCore.jar")>
<cfset loader = createObject("component","qrJavaLoader.JavaLoader").init(paths)>
<cfset BarcodeFormat = loader.create('com.google.zxing.BarcodeFormat')>
<cfset QRCodeWriter = loader.create('com.google.zxing.qrcode.QRCodeWriter').init()>
<cfset MatrixToImageWriter = loader.create('com.google.zxing.client.j2se.MatrixToImageWriter')>


<cfset QRText="Created at " & dateTimeFormat(NOW(), 'yyyy-mm-dd HH:nn:ss') & " by https://github.com/mohokh67">
<cfset QRcode=QRCodeWriter.encode("#QRText#",BarcodeFormat.QR_CODE,200,200)>
<cfset image=ImageNew( MatrixToImageWriter.toBufferedImage(QRcode))>
<cfset QRImageFilename="qrTest.png">
<cfimage action="write" source="#image#" format="png" destination="#expandPath(QRImageFilename)#" overwrite="true" quality="1">

<cfdocument  format="pdf" fontEmbed="Yes" pageType="A4" unit="cm" marginbottom="0" margintop="0" marginleft="0" marginright="0" overwrite="yes">
	<h1>Scan this QR code please...</h1>
	<img src='qrTest.png'>
</cfdocument>