Skip to main content
Participating Frequently
July 31, 2014
Answered

Anyone use <cfdocument> tag with a <cfloop>

  • July 31, 2014
  • 2 replies
  • 743 views

Anyone use <cfdocument> tag with a <cfloop>

I am trying to generate multiple documents like this -

<cfloop query="myquery">

   <cfdocument type=pdf>

        <html>...html code here...<html>

  </cfdocument>

</cfloop>

But only the first document is generated in the browser?



my requirement i wnat to create multiple PDF and upload in to folder then zip folder so user can able to download ZIP file


thanks in advance

This topic has been closed for replies.
Correct answer BKBK

my requirement i wnat to create multiple PDF and upload in to folder then zip folder so user can able to download ZIP file

1) Create a folder named, say, docsDir, in the currect directory.

2) Create the PDFs, using Eddie Lotter's suggestion, naming each file dynamically, and storing each in the folder docsDir.

<cfloop query="myquery">

    <!--- Use row number to create filename dynamically --->

   <cfset filename='doc' & myquery.currentRow & '.pdf'>

   <cfdocument format="pdf" filename="#expandPath('docsDir\#filename#')#" overwrite="true">

        <html> Code to generate content of <cfoutput>#filename#</cfoutput> goes here. </html>

  </cfdocument>

</cfloop>

3) Zip the folder, docsDir, storing the resulting file, docsDir.zip, in the current directory.

<cfzip action="zip" file="#expandPath('.')#/docsDir.zip"   source="#expandPath('docsDir')#">

2 replies

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
August 2, 2014

my requirement i wnat to create multiple PDF and upload in to folder then zip folder so user can able to download ZIP file

1) Create a folder named, say, docsDir, in the currect directory.

2) Create the PDFs, using Eddie Lotter's suggestion, naming each file dynamically, and storing each in the folder docsDir.

<cfloop query="myquery">

    <!--- Use row number to create filename dynamically --->

   <cfset filename='doc' & myquery.currentRow & '.pdf'>

   <cfdocument format="pdf" filename="#expandPath('docsDir\#filename#')#" overwrite="true">

        <html> Code to generate content of <cfoutput>#filename#</cfoutput> goes here. </html>

  </cfdocument>

</cfloop>

3) Zip the folder, docsDir, storing the resulting file, docsDir.zip, in the current directory.

<cfzip action="zip" file="#expandPath('.')#/docsDir.zip"   source="#expandPath('docsDir')#">

Bibin-_V-Author
Participating Frequently
August 2, 2014

It is working fine.... thank you (y)

EddieLotter
Inspiring
July 31, 2014

If you want to write the document to a file, your cfdocument tag must include the filename attribute.

Did you perhaps just leave that out of the example you posted?

Bibin-_V-Author
Participating Frequently
August 2, 2014

thank you