Skip to main content
nikos101
Inspiring
February 11, 2010
Answered

I was not allowed to deleted them pdf's until I had restarted CF

  • February 11, 2010
  • 4 replies
  • 5436 views

I have my CF server generate lots of pdfs but when I got to around 270 lying in a folder I was not allowed to deleted them pdf's until I had restarted CF,

any ideas why this could have occured?

    This topic has been closed for replies.
    Correct answer MarkMetcalf

    I'm late to the conversation, but I had the same problem with populating a PDF form with data, saving that PDF, then flattening the PDF.

    Here's how I solved it in CF9:

    <cfset path = "#GetDirectoryFromPath(GetCurrentTemplatePath())#doc\">
    <cfset srcFile = "template\myPDFtemplate.pdf">
    <cfset destFile = "yourPDF.pdf">

    <!--- Using NAME instead of DESTINATION tells Coldfusion to create PDF in memory --->
    <cfpdfform action="populate" source="#path##srcFile#" name="#destFile#">
        <cfpdfformparam name="field1" value="some value">
    </cfpdfform>

    <!--- Using the variable in the SOURCE tells Coldfusion to read PDF from memory --->
    <cfpdf action="write" destination="#path##destFile#" source="#destFile#" flatten="yes" overwrite="yes" />

    Hope this helps others.

    Mark

    4 replies

    MarkMetcalfCorrect answer
    Participant
    September 17, 2010

    I'm late to the conversation, but I had the same problem with populating a PDF form with data, saving that PDF, then flattening the PDF.

    Here's how I solved it in CF9:

    <cfset path = "#GetDirectoryFromPath(GetCurrentTemplatePath())#doc\">
    <cfset srcFile = "template\myPDFtemplate.pdf">
    <cfset destFile = "yourPDF.pdf">

    <!--- Using NAME instead of DESTINATION tells Coldfusion to create PDF in memory --->
    <cfpdfform action="populate" source="#path##srcFile#" name="#destFile#">
        <cfpdfformparam name="field1" value="some value">
    </cfpdfform>

    <!--- Using the variable in the SOURCE tells Coldfusion to read PDF from memory --->
    <cfpdf action="write" destination="#path##destFile#" source="#destFile#" flatten="yes" overwrite="yes" />

    Hope this helps others.

    Mark

    nikos101
    nikos101Author
    Inspiring
    May 28, 2012

    is this bad bug fixed in CF10??

    Known Participant
    June 16, 2010

    If I put a cflock around the cfpdfform, the resulting file does not stay locked open.

    However, the subsequent cfpdf flatten call still fails, whether inside a cflock or not.

    I submitted bug 83365 on this issue.

    Charlie Arehart
    Community Expert
    Community Expert
    June 17, 2010

    Folks, I don't see anyone suggesting one feature that may help here. You don't really need to create files with these CFPDF* tags if you don't want to.

    For instance, as seems Paule's issue, if one tag creates something that then another would use (as his CFPDFFORM result then being flattened), you can use the NAME attribute (instead of destination) to indicate a variable to hold the output of an earlier step, and then use that variable in the SOURCE of a later step.

    I do realize that some may want to create the files intentionally, but perhaps at least if you only do it on the last step, it may resolve his problem.

    As for earlier notes saying that files remain locked even after the request is finished, that's not something I've seen or know anything more about.

    Just throwing this variable idea out if it will help anyone.

    /charlie

    /Charlie (troubleshooter, carehart. org)
    Known Participant
    June 17, 2010

    Charlie,

    I like the idea, but I'm looking at the CF9 docs on CFPDFFORM, and it doesn't appear to be able to output to a variable... there's no "name" parameter as there is in CFPDF.  There's a line in the docs that say:

    "For forms created in Acrobat, you can write the output to a PDF file only."

    Anyhoo, Adobe just emailed me a confirmation a little while ago confirming the bug, so hopefully it's fixed in the next update...

    Known Participant
    June 16, 2010

    Was there any resolution to this problem?   We just upgraded from CF8 to CF9 a couple days ago, and it appears cfpdfform is locking files open and causing our code to error out.

    Our sequence is to do a cfpdfform to fill in form data, then we do a cfpdf to flatten the same source/destination file with overwrite.  This worked perfectly in CF8, now we've got a serious problem with CF9.

    The cfpdf error is:

    ColdFusion could not delete the file D:\mysites\blabla\contract_509.pdf.
    Check if another request or process is not using the file.

    nikos101
    nikos101Author
    Inspiring
    June 16, 2010

    I just do a different name for flatten, I don't bother with the ideal override

    I feel your pain buddy

    nikos101
    nikos101Author
    Inspiring
    February 11, 2010

    The funny thing now when I try to create a pdf I get the following error from colfusion

    faultCode:Server.Processing faultString:'Unable to invoke CFC - ColdFusion could not delete the file C:\Inetpub\wwwroot\FLEX\bookingsystem\pdfToSend/OPT-000000-295.pdf.' faultDetail:'Check if another request or process is not using the file.'

    Im trying to do this: I'm not trying to delete anyting:


      <cfset out =  GetDirectoryFromPath(
    GetCurrentTemplatePath()
    ) & "pdfToSend/#arguments.ref#.pdf">


      <cfpdfform source="#source#"
        destination="#out#" action="populate"  overwrite="yes" 
        >
        <cfpdfformparam name="1" value="#arguments.fields._1#">
        <cfpdfformparam name="29" value="#arguments.fields._29#">
      </cfpdfform>


      <cfpdf action="write" flatten="yes" source="#out#"
        destination="#out#" overwrite="yes"> </cfpdf>

    nikos101
    nikos101Author
    Inspiring
    February 11, 2010

    The weird thing is is that the PDF is created fine, then the error is thrown and my following email code is not excecuted:

    <cfmail type="html" to="#email#"
                    from="#arguments.Email#"  subject="FX"
                            mimeattach="#out#"
                   

    BKBK
    Community Expert
    Community Expert
    February 14, 2010

    Coldfusion may be attempting to write to the PDF file while reading it for the email. Test with a named lock, as follows:

    <cflock name="out_pdf_lock" timeout="10" type="exclusive">
          <!--- the pdf code goes in here --->
    </cflock>

    <cflock name="out_pdf_lock" timeout="10" type="exclusive">
          <!--- the mail code goes in here --->
    </cflock>