这个脚本工作正常。我遇到的问题是试图让它每页生成多个条形码。它只会生成第一个。其余的是空白图像。
<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>