6 Replies Latest reply on Mar 15, 2010 1:16 PM by Dan Bracuk

    how to call a CF File from another CF File

    Ravi.Kanchiraju

      Hi

       

      I am trying to call a CF1 File from another CF2 File.

       

      CF1 File - takes some parameters which will help in generating PDF.

       

      i need to call that CF1 File with parameters from another CF2 File. i cannot use hyperlink, i cannot use cflocation, i cannot use cfform tag, i cannot use any submit buttons or anything. just when i run CF2 File. CF1 File should trigger and the pdf output should be generated.  pdf output will only be generated in cf1 file only when i send some parameters to that file from CF2 File.

       

      Thanks

      Ravi

        • 1. Re: how to call a CF File from another CF File
          existdissolve Level 2

          What about invoking a cfc?

          • 2. Re: how to call a CF File from another CF File
            Ravi.Kanchiraju Level 1

            can you give me example code.

            • 3. Re: how to call a CF File from another CF File
              existdissolve Level 2

              This is CERTAINLY not the most elegant solution, but it shows the intention, at least.

               

              First, on the calling page, we have the following CFC invocation (it assumes a folder structure of root/com/excel.cfc):

               

              <cfinvoke component="com.excel" method="makePDF" firstname="Douglas" lastname="Adams" />

               

              The "component" attribute tells CF where to look for the cfc file and the "method" attribute tells CF which "method" to run once it finds the cfc.  Next, I simply pass in a couple arguments: firstname and lastname in this example.  Of course, these could just as easily be FORM or URL variables (or any other kind, for that matter.

               

              Next, here's the CFC:

               

              <cfcomponent>
                  <cffunction name="makePDF" access="public" output="yes">
                      <cfargument name="firstname" required="yes">
                      <cfargument name="lastname" required="yes">
                      <cfsavecontent variable="pdfdoc">
                          #arguments.firstname# #arguments.lastname#
                      </cfsavecontent>
                      <cfheader name="content-disposition" value="attachment; filename=mypdf.pdf">
                      <cfdocument format="pdf">
                          <cfoutput>#pdfdoc#</cfoutput>
                      </cfdocument>
                  </cffunction>
              </cfcomponent>

               

              You'll notice at the top I have the arguments expected for this method specified--the same two that I passed from the calling page.  Next, I simply create the document content.

               

              The most important part is the <cfheader>--by setting the "value" to what it is, it will force a download of the pdf, rather than trying to load it in the same page.  Finally, I just output the document content between <cfdocument> tags with a format of "pdf" which will take care of the pdf generation.

               

              Again, not the most elegant solution, but I think it will work.  Hope it helps.

              • 4. Re: how to call a CF File from another CF File
                Ravi.Kanchiraju Level 1

                Thanks for taking time and replying to my post.

                 

                I am not sure how can i use your example but here is what i have. i have a coldfusion file2 that uses cfdocumentitem to generate pdf. for this file i need to just pass one value(ex like emp id) from another file. not only passing value. but the file2 should be called from file1 with that parameter. until unless it
                (file2) calls the file(file1) with parameter, pdf file will not be generated. like cflocation how it calls another cfpage with parameters. is there anyway. i cannot use cflocation bec it is redirecting.

                 

                let me know if i am clear to you or not.