Very strange, but repeatable issue I've run into. I'm using the barbecue Java barcode generator library to generate code128 compliant barcodes which are then handed to cfimage writeToBrowser to finally end up with printable packing/mailing labels. When rendered to screen, everything works perfectly, but as soon as I wrap it in a cfdocument tag, so that we can generate as a pdf for printing on a label printer, I'm ending up with the wrong image on the wrong label in a few cases. It's always the same records that end up reusing an image from an earlier record (and always the same earlier record). I can check in the ColdFusion8\tmpCache\CFFileServlet\_cf_image folder and see that all the correct images were created by the cfimage tag, but for whatever reason, some of the images don't make it into the pdf, but are replaced by a different barcode from an earlier record. I can't see any commonality between the two records and if I intentionally remove the earlier record from the query, the proper barcode shows up.

So, any ideas about where to go from here? Anybody know anything about how cfdocument pulls in images and if there is any kind of caching or prechecking of the images before rendering. I actually checked to make sure the two files didn't have the same MD5 sum to see if there was something happening there where CF thinks it's the same image. They were not the same.

I've tried this on two CF 8.01 boxes with the same result. Always the same records, same images, same problem, even if I limit the query to only the two problem records. I'm totally stumped. Anybody?

Not sure it's helpful, but here's the code, at least the relevant parts. As I said, I've confirmed that this is all doing what it's supposed to and if I take off the cfdocument, it renders to the screen perfectly every time.

I notice there is lot of looping and grouping going on. Any chance it is related? If you output the "bcText" at each step (inside the pdf) is the value correct? Also, for grins you might output the image URL and confirm whether it is repeating, or the "bcText" is repeating.

Well, we're on the same page there. I've done all that you've mentioned and it's always correct (keep in mind, outputing to screen is always working, it's just inside cfdocument that I see this problem and it's always the same records). The grouping and looping is defintely working as expected and urls to images are the correct urls, even in the pdf, but the image is not what the url is pointing to. I've pretty well convinced myself that it has to be something about how cfdocument gets images.

As one more piece of data to add, I just tried adding a random integer at the beginning of the bcText, which obviously then generates a different barcode image and it worked correctly, even in the pdf. So it's something about the particular image files that get created. I'm thinking only an Adobe CF engineer with knowledge of the inner workings of cfdocument is going to be able to help me. Anyone know who that might be?

Not sure it's helpful, but here's the code, at least the relevant parts. As I said, I've confirmed that this is all doing what it's supposed to and if I take off the cfdocument, it renders to the screen perfectly every time.

Nope. All grouping and loops are necessary based on the shape of the data and the required output based on the number of labels required for each row in the source query. I'm doing something at each stage of the grouping (although I removed some of that because it wasn't really relevant to the question) to build these labels. I'm quite confident that the grouping and looping is correct and not part of the problem. In fact, I've built a simple test page that removes all the complexity of my grouping and query and will still produce this problem (although you have to have the barbecue library to test).

Yep, that is why I said all function local variables. I was only trying to highlight the fact that were no VAR scope declarations at the top of the function. (I did not look over the variable names in detail :-)

Yep, that is why I said all function local variables. I was only trying to highlight the fact that were no VAR scope declarations at the top of the function. (I did not look over the variable names in detail :-)

Nice of you, but you needn't explain. It was an oversight. I was already thinking VAR myself, and so just skimmed 'barcode' and 'VAR'. Sorry.

Nope. All grouping and loops are necessary based on the shape of the data and the required output based on the number of labels required for each row in the source query. I'm doing something at each stage of the grouping (although I removed some of that because it wasn't really relevant to the question) to build these labels. I'm quite confident that the grouping and looping is correct and not part of the problem. In fact, I've built a simple test page that removes all the complexity of my grouping and query and will still produce this problem (although you have to have the barbecue library to test).

The question remains why it fails with, but works without, cfdocument. Does cfdocument introduce a new page context? I wonder. If so, then what -==cfSearching==- said about varring the variables would immediately make sense. Unvarred variables belong to the context of the current page.

Another issue may arise from <cfloop list="#list#" index="i">. You implicitly assume that ColdFusion will process the list elements in the exact order in which they appear in the list. I suspect ColdFusion wont always. It may internally apply some kind of sorting, and begin with the last element in the list.

@BKBK: I don't want to sidetrack the thread here, but that last statement about assuming the order of processing on a list in the CFLOOP tag is pretty concerning. I've never witnessed any behavior other than processing the list exactly in the order provided, and I have a hard time believing that we've just been lucky for 15 years. That /is/ in fact a key assumption in lots of CFML code. Do you have a basis for that statement, either in the docs or repeatable behavior in code you can share? To have them processed in anything other than the order provided seems so counterintuitive as to render the whole concept of using a list to drive any sort of iteration as basically useless...

@BKBK: I don't want to sidetrack the thread here, but that last statement about assuming the order of processing on a list in the CFLOOP tag is pretty concerning. I've never witnessed any behavior other than processing the list exactly in the order provided, and I have a hard time believing that we've just been lucky for 15 years. That /is/ in fact a key assumption in lots of CFML code. Do you have a basis for that statement, either in the docs or repeatable behavior in code you can share? To have them processed in anything other than the order provided seems so counterintuitive as to render the whole concept of using a list to drive any sort of iteration as basically useless...

No need worrying or running for the hills, Ron. I wrote that piece without due attention. What I omitted says more about what I was thinking.

I was trying to puzzle out why ColdFusion would start looping a list at position 2, or at any position other than 1 for that matter. What I wished I had said follows.

Another issue may arise from <cfloop list="#list#" index="i">. If the list is indeed as it appears in the code, then there is no issue. However, suppose the list was comprised of the keys of a struct. That is, the list of keys is structKeyList(theStruct), and you've stated the list in the code as a simplified test page. You implicitly assume that ColdFusion will process the list elements in the exact order in which they appear in the list. I suspect ColdFusion wont always. It may internally apply some kind of sorting, and begin with the last element in the list.

These are the two images I pulled from the temp directory where cfimage creates them. Moved them to my test folder and ran the above code and got a pdf with the correct image in the first image tag, but then the same image repeated in where the second image should have been. And before you ask, yes, I'm certain the images are different. In fact, here they are:

As before, running without the cfdocument tags renders the correct images in the correct spots. Can we now just agree that cfdocument is the culprit and maybe at least an acknowledgement from an Adobe rep that there may be an issue here?

@BKBK: No worries here. If I get the gist of your comment, it was centered around the question of whether the list itself was ordered as expected rather than whether the list was iterated over in order from first to last?

jeff.c sent me a copy of his code and image files referenced above, and I have duplicated this behavior on a fully-updated 9.01 box. Same exact behavior, so it is clearly not something unique to 8.01 or something that has been patched in 9.x. I have a CF10 box I will try this on in a bit, as well...

maybe at least an acknowledgement from an Adobe rep that there may be an issue here?

Well these are user-to-user forums. If you want to speak with an adobe representative, you need to use official channels. (While I have seen an occaisional comment here and there, it is rare. So it is extremely unlikely you would get a response from an Adobe employee here).

@BKBK - Your test would validate my hypothesis that cfdocument is doing something to look at the images and determine if they have already been loaded and, if so, reuse the already loaded image. Whatever that comparison is based on is treating these two images as the same image. Since you've altered the original image, I'm not surprised that it now works correctly, but if you go back to the original images, unaltered, I'm quite confident you'll see the same behavior. For what it's worth, I compared the MD5 sum of the two images and they do not match.

@cfSearching - What you're seeing would also validate what I'm thinking. Once you include the text, you've fundamentally altered the signature of the image and cfdocument isn't mistaking them anymore. I'm not comfortable just including the barcode text though and hoping that it solves the problem. In my mind, it's still possible and likely that the underlying engine could still be confused in comparing images when I'm generating hundreds of these barcodes in a pop, and if it only happens very occasionally, then it's almost more problematic since I'd have to validate every single label to make sure it's right. In any case, you're right. I think I need to try and get some help from Adobe. I'm filing a bug right now.

@BKBK - Your test would validate my hypothesis that cfdocument is doing something to look at the images and determine if they have already been loaded and, if so, reuse the already loaded image. Whatever that comparison is based on is treating these two images as the same image. Since you've altered the original image, I'm not surprised that it now works correctly, but if you go back to the original images, unaltered, I'm quite confident you'll see the same behavior. For what it's worth, I compared the MD5 sum of the two images and they do not match.

Your confidence is justified! I reran my above test with the original image. I did reproduce the issue.

I think I was finally able to reproduce the behavior on 9.01. But it only happens when setDrawingText(..) is false.

I further tested the same code on CF 10 Beta. Irrespective of whether I used barcode.setDrawingText(false) or barcode.setDrawingText(true), I did reproduce the issue. Also, when I changed the order of the numbers from ["00413001811","00403001811"] to ["00403001811","00413001811"], the barcode image changed, but the issue persisted.

Leigh, you might want to change the text rendered red in your code to quoted strings.

Yes, you are right but that is courtesy of this lovely forum software ;-). After it mangled the original (with quotes) three times, I finally gave up. I am not sure it lets you edit posts after other responses are added. I will check the web interface later.

I used the following simplified code, and tried every which way to not reproduce the cfdocument problem. For example, I displayed the images on a separate CFM page, downloaded the page by cfhttp, and used cfdocument to display the page content. All my attempts failed. The problem persists.

FWIW, I was able to get past this issue by changing the cfimage tag to produce jpg images rather than png. Now, I have no way of knowing if this actually solved the problem or simply fixed it for these two images I was comparing and if I will now have to be on the lookout for other images with the same problem.

I did get a reply from Rupesh Kumar (Adobe CF Engineer) from a question I submitted on his ColdFused blog where he stated that the thought this had been fixed in 9.01. I assured him it had not and pointed him to the bug I filed.

I did get a reply from Rupesh Kumar (Adobe CF Engineer) from a question I submitted on his ColdFused blog where he stated that the thought this had been fixed in 9.01. I assured him it had not and pointed him to the bug I filed.

Well at least now you have a firm confirmation of your suspicion it is a it is a bug. Since it sounds like a known issue, did he mention anything about cause or possible work-arounds?

I'm having the same problem. Before read this topic, I already knew that when you setDrawingText(false) the problem happens and I still need to solve this problem too. I wonder stop use barbecue and try use ".ttf" fonts. Somebody used ".ttf" fonts and got a good result?