Skip to main content
Inspiring
January 14, 2009
Question

cflock and iText

  • January 14, 2009
  • 2 replies
  • 735 views
Developers,

I'm using CFMX 7 with iText. I have a form in which users can select multiple pdf documents via checkboxes. After selecting a number of checkboxes, they can either immediately hit the Submit button to merge (using iText) all selected documents, or from a dropdown box, select an image to be applied to the top of each document, and then hit Submit, which will merge the documents first, then apply the image to each page of the merged documents. (reference this post for additional information: iText Watermark position issue)

The merging and watermarks work great; however the problem I'm having now is what appears to be file corruption. Every now and again, when a user selects the documents and an image, the page processes, but returns a previously merged document with a previous image applied. Looking at merged file on the server confirms that the file is corrupt and sometimes I am able to delete the file and then future selections merge correctly.

So I figured I could apply cflock - as this must be a race condition issue - to prevent the corruption. However, I don't think I fully understand it as it does not appear to be working. I have some documentation where you are supposed to name the locks the same and other documentation states to name one readonly and the other exclusive.

Attached is my code below. Can someone please look and give advice as how to proceed? Also, I can include the code from mergeOnly.cfm and mergeWatermark.cfm if necessary.

Thanks.

This topic has been closed for replies.

2 replies

Inspiring
January 14, 2009
Also, if you are replacing an _existing_ file, you might consider using a temporary file, to avoid locking the entire call. Then at the end, replace the existing file with the temporary one, and delete the temp file.

Here is a good link on locking file renames:
http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49321#263456
Inspiring
January 14, 2009
> but returns a previously merged document with a previous image applied.

First thing I would ask is whether you checking the returned status of the insertWatermarkPDF function. So you can determine when an error occurs and perform a different action if one did ..