Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFLOOP LIST & CFDOCUMENT

Participant ,
Mar 27, 2019 Mar 27, 2019

I have code to create a pdf like this. It works great

<cfdocument format="pdf" localUrl="yes" orientation="landscape" marginleft="0.10" marginright=".10" margintop="0.15" >

<cfdocumentitem type="footer"> <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</cfoutput> </cfdocumentitem>

<cfquery name="Loads" datasource="dsn">

SELECT  [company_id]

FROM datatable

WHERE ID  =16598

</cfquery>

Rest of code based on ID

</cfdocument>

Now I want to loop through a list of ID's and create a combined pdf of all of the ID's in the list

like this

<cfloop list="16958,17019,17020"  index="idx">

<cfdocument format="pdf" localUrl="yes" orientation="landscape" marginleft="0.10" marginright=".10" margintop="0.15" >

<cfdocumentitem type="footer"> <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</cfoutput> </cfdocumentitem>

<cfquery name="Loads" datasource="dsn">

SELECT  [company_id]

FROM datatable

WHERE ID  =#idx#

</cfquery>

Rest of code based on ID

</cfdocument>

</cfloop>

But when I do this only the first pdf prints.

So in my example, the pdf for 16958 is generated but not 17019 or 17020

What am I doing wrong?

2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 28, 2019 Mar 28, 2019

If you want a single document, move the loop inside of the cfdocument tag.

Translate
Community Expert ,
Mar 27, 2019 Mar 27, 2019

It's going to be one PDF at a time. If you want to generate more, then do something like

<cfloop list="16958,17019,17020"  index="idx">

    <cfquery name="Loads" datasource="dsn">

    SELECT  [company_id]

    FROM datatable

    WHERE ID  =#idx#

    </cfquery>

    <cfdocument format="pdf" localUrl="yes" orientation="landscape" marginleft="0.10" marginright=".10" margintop="0.15" filename="#expandPath('doc#idx#.pdf')#" overwrite="yes">

    <cfdocumentitem type="footer"> <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#  </cfoutput> </cfdocumentitem>

    Rest of code based on ID

    </cfdocument>

</cfloop>

That will save each PDF as a separate file within the current directory.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 28, 2019 Mar 28, 2019

This is exactly what I have now and it only generates 1 pdf form the list

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 28, 2019 Mar 28, 2019

weezerboy  wrote

This is exactly what I have now and it only generates 1 pdf form the list

Not according to the code your provided. You have the cfdocument tag inside the cfloop tag. You need it to be the other way around.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 28, 2019 Mar 28, 2019

sorry, Eddie. I thought I was replying to BKBK.

On your suggestion. I tried this too but I've got some cached content that is causing issues when I try it the way you suggested.

Anyway I'll try it again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 28, 2019 Mar 28, 2019

Ah. Then, as EddieLotter​ suggests,

<cfdocument format="pdf" localUrl="yes" orientation="landscape" marginleft="0.10" marginright=".10" margintop="0.15">

    <cfloop list="16958,17019,17020"  index="idx">

        <cfquery name="Loads" datasource="dsn">

            SELECT  [company_id]

            FROM datatable

            WHERE ID  =#idx#

        </cfquery>

       

        <!--- Remember to use fully qualified, that is, scoped names. For example, Loads.ID --->

                

        Rest of code based on ID

       

        <cfdocumentitem type="footer"> <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#  </cfoutput> </cfdocumentitem>

       

    </cfloop>

</cfdocument>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 28, 2019 Mar 28, 2019

Sorry I've got some issue with my document body code that's not allowing me to do what you suggested.

So I was thinking now to somehow loop through and create and save individual pdf for each idx and then once I have all of the pdfs from the list created then create a new pdf and combine all of the pdfs together to create 1 document.

Any suggestions on how to create and save the pdfs to a directory? Once they are there I can do the pdf merge to put them into 1 document.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 29, 2019 Mar 29, 2019
LATEST

weezerboy  wrote

Sorry I've got some issue with my document body code that's not allowing me to do what you suggested.

That doesn't make sense to me. Whether you write to a single file or multiple files doesn't change the document body, only where the loop goes.

weezerboy  wrote

So I was thinking now to somehow loop through and create and save individual pdf for each idx and then once I have all of the pdfs from the list created then create a new pdf and combine all of the pdfs together to create 1 document.

Any suggestions on how to create and save the pdfs to a directory? Once they are there I can do the pdf merge to put them into 1 document.

Use the filename attribute of the cfdocument tag to write to a file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 28, 2019 Mar 28, 2019

If you want a single document, move the loop inside of the cfdocument tag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources