【问题标题】:Cold Fusion QR Image - JAVA Path冷融合 QR 图像 - JAVA 路径
【发布时间】:2021-03-05 20:05:08
【问题描述】:

我不擅长 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"

【问题讨论】:

标签: java coldfusion coldfusion-2016


【解决方案1】:

我将此功能与谷歌二维码应用程序使用的zxing(包括chart.apis.google.com)结合使用。您需要下载core-3.4.0.jarjavase-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>

【讨论】:

  • 是的。更简单的是,通过 Application.cfc 的 this.javaSettings 加载 jar。
【解决方案2】:

这可能更简单。

      <cfhttp url="http://chart.apis.google.com/chart?chs=250x250&cht=qr&chl=http://www.website.com" result="qrcode" getasbinary="yes">
      <cfimage action="writeToBrowser" source="#qrcode.filecontent#" style="height:250px;width:250px">

所以我会玩一会儿,然后尝试保存 Google 拉取。 其他二维码比较老了。

是的,更简单。嗅探 qrimg 是否完成,如果没有创建它。

      <cfif qrimg is "">


      <cfhttp url="http://chart.apis.google.com/chart?chs=250x250&cht=qr&chl=http://webaddress?vid=#vid#&src=p" result="qrcode" getasbinary="yes">

      <cfimage action="writeToBrowser" source="#qrcode.filecontent#" style="height:250px;width:250px">

      <cfimage action="write" source="#qrcode.filecontent#" destination="#expandPath( 'QR_#vid#.jpg' )#" overwrite="true">

      #vnumber# : #vname#<br>

            <cfquery name="nm" datasource="#fds#">
              update fv
              set qrimg = 'QR_#vid#.jpg'
              where vid = '#vid#'
            </cfquery>

      <cfelse>
      <img src="QR_#vid#.jpg">
      <br>
      #vnumber# : #vname#<br>
      </cfif>

【讨论】:

  • 有没有办法同时激活相机进行二维码扫描。来自网页。避免导航点击。他们只是从他们所在的页面内扫描?
猜你喜欢
  • 1970-01-01
  • 2011-01-09
  • 1970-01-01
  • 2011-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-20
  • 1970-01-01
相关资源
最近更新 更多