【发布时间】:2017-02-03 06:52:54
【问题描述】:
这个脚本运行良好。我遇到的问题是试图让它每页生成多个条形码。它只会生成第一个。其余的都是空白图像。
<cfoutput>
<cfset x = 0>
<cfloop index="price_tag" from="1" to="#arrayLen( session.tags )#">
<cfset x = x + 1>
<cfscript>
code128= createobject("java","com.lowagie.text.pdf.Barcode128");
code128.setCodeType(code128.CODE128);
/* Set the code to generate */
code128.setCode("#Session.tags[price_tag].itemnum#");
color = createobject("java","java.awt.Color");
image = code128.createAwtImage(color.black, color.white);
bufferedImage = createObject("java", "java.awt.image.BufferedImage");
bufferedImageType = bufferedImage.TYPE_BYTE_GRAY;
bufferedImage = bufferedImage.init(image.getWidth(JavaCast("null", "")),image.getHeight(JavaCast("null", "")), bufferedImageType);
graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(image,0,0,JavaCast("null", ""));
barcodeImage = imageNew(bufferedImage);
</cfscript>
<div style="margin:0px; padding:0px;">
<div style="font-size:42px; font-weight:bold; margin-bottom:0px; margin-right: 10px; margin-top: -5px;">#Session.tags[price_tag].item_name#</div>
<div style="font-size:32px; margin-bottom:0px; margin-top:-7px; margin-right: 10px;">#Session.tags[price_tag].item_brand#</div>
<div style="font-size:24px; margin-bottom:0px; margin-top:-7px;">#Session.tags[price_tag].item_unit_size# #Session.tags[price_tag].item_unit_type# </div>
<div style="font-size:120px; font-weight:bolder; margin-top:-55px; margin-right: 10px;" align="right">#DollarFormat(Session.tags[price_tag].item_retail)#</div>
<div style="font-size:30px; font-weight:bolder; margin-top:-30px; margin-right: 10px;" align="right"> #Session.tags[price_tag].item_sold_by#</div>
<div style="font-size:30px; margin-top:-35px; margin-left 10px;" align="left">#Session.tags[price_tag].itemnum#</div>
<div style=" position:absolute; margin-left: 10px; margin-top: 100px;"><cfimage action="writeToBrowser" source="#barcodeImage#" format="png" quality="1" width="180px" overwrite = "yes"></div>
</div>
<cfif #arrayLen( session.tags )# / #x# NEQ 1>
<cfdocumentitem type="pagebreak"/>
</cfif>
</cfloop>
</cfoutput>
【问题讨论】:
-
在脚本中输出x、价格标签等各种变量。这将帮助您确定正在发生的事情。可能与您的问题无关,但您可以在开始循环之前创建 java 对象并在循环中使用它们。
-
不使用
<cfset x = x + 1>,而是将其跟踪为#price_tag#。处理的变量少了一个。 -
尝试取出
overwrite = "yes"。当你action="writeToBrowser"时,我认为你不需要那个。 -
CFDocument 总是有点古怪。我怀疑可能与此有关:
<div style=" position:absolute;如果删除它,就会出现条形码。
标签: coldfusion cfdocument cfimage