首页 > 解决方案 > 冷融合 QR 图像 - JAVA 路径

问题描述

我不擅长 JAVA

我从这里开始使用 QRToad https://github.com/boltz/QRToad

ColdFusion 2016 - MS Server 2016:我已经重新启动了几次 cf 服务器。

我在第 5 行收到错误

找不到类:com.itextpdf.text.pdf.BarcodeQRCode

错误发生在

C:/upcloud/_live_websites/_silkea/test/QR/com/timcunningham/QRToad/QRCode.cfc: line 5
Called from C:/upcloud/_live_websites/_silkea/test/qr/getqrtest.cfm: line 2
Called from C:/upcloud/_live_websites/_silkea/test/QR/com/timcunningham/QRToad/QRCode.cfc: line 5
Called from C:/upcloud/_live_websites/_silkea/test/qr/getqrtest.cfm: line 2

3 :                     put the itext JAR in your ColdFusion class path. 
4 :                     Restart ColdFusion service">
5 : <cfset QR = createObject("java","com.itextpdf.text.pdf.BarcodeQRCode")>

这是 JAR:itext-pdfa-5.5.13.2.jar

我把它放在:C:\ColdFusion2016\jre\lib 和 C:\ColdFusion2016\cfusion\lib

我把它放错地方了吗?还是我需要改变这个?

"java","com.itextpdf.text.pdf.BarcodeQRCode"

标签: javacoldfusioncoldfusion-2016

解决方案


我将此功能与谷歌二维码应用程序(包括)使用的zxingchart.apis.google.com结合使用。您需要下载core-3.4.0.jar并将javase-3.4.0.jar它们放入C:\ColdFusion2016\cfusion\lib

<cfscript>
  public string function createQRCode( 
    required string data,
    integer width=180,
    integer height=180,
    integer margin=4,
  ){
    local.filePath = getTempDirectory() & application.fwUtilService.generateUUID() & '.png';
    local.objQRCodeWriter = CreateObject('java', 'com.google.zxing.qrcode.QRCodeWriter');
    local.objBarcodeFormat = CreateObject('java', 'com.google.zxing.BarcodeFormat');
    local.objEncodeHintType = CreateObject('java', 'com.google.zxing.EncodeHintType');
    local.objHashMap = CreateObject('java', 'java.util.HashMap');
    local.objFileSystems = CreateObject('java', 'java.nio.file.FileSystems');
    local.objMatrixToImageWriter = CreateObject('java', 'com.google.zxing.client.j2se.MatrixToImageWriter');
    local.qrCodeWriter = local.objQRCodeWriter.init();
    local.objHashMap.put(local.objEncodeHintType.MARGIN, javacast('int', arguments.margin));
    local.objHashMap.put(local.objEncodeHintType.CHARACTER_SET, "UTF-8");
    local.objEnumMap = CreateObject('java', 'java.util.EnumMap').init(local.objHashMap);
    local.bitMatrix = local.qrCodeWriter.encode(data, local.objBarcodeFormat.QR_CODE, arguments.width, arguments.height, local.objEnumMap);
    local.path = local.objFileSystems.getDefault().getPath(local.filePath, []);
    local.objMatrixToImageWriter.writeToPath(local.bitMatrix, "PNG", local.path);
    return local.filePath;
  }
</cfscript>

推荐阅读