Coldfusion cfimage条形码生成器(生成多个条形码)

时间:2017-02-03 06:52:54

标签: coldfusion cfdocument cfimage

这个脚本运行正常。我遇到的问题是试图让它每页生成多个条形码。它只会生成第一个。其余的都是空白图像。

<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>

1 个答案:

答案 0 :(得分:0)

这可能是因为您在cfdocument中的循环中使用action="writeToBrowser"。它不会用于浏览器。

尝试编写真实文件,然后链接到它们。我做到了,知道它有效。确保在该循环中使用不同的文件名。

如果您打算一遍又一遍地运行此例程,则可以安全地使用相同的文件名。但是在您的代码中禁用了带有url var:

的图像src的缓存
<cfoutput>
<img src="/media/cms/code-#price_tag#.png?rand=#randRange(0,1000)#" width="180"/>
</cfoutput>
相关问题