4

I have the following cfdocument code:

<cfdocument format="pdf" orientation = "landscape" bookmark="Yes" marginleft=".25" marginright=".25" marginTop = ".75" marginbottom=".75" scale="90" localUrl="yes"> 
    <cfoutput>
        <cfdocumentsection name="Summary Page" marginleft=".25" marginright=".25" marginTop = "1.65" marginbottom="1" >
            <cfdocumentitem type="header">
                <center>
                    <table width="1000" height="200" cellpadding="3" cellspacing="0">
                        <tr><td>Header Page</td></tr>
                    </table>
                </center>
            </cfdocumentitem>

            <cfloop query="first_query">
                <cfquery name="getDetails" dbtype="query">
                    select * from first_query
                    where type= <cfqueryparam cfsqltype="cf_sql_varchar" value="#Type#">
                </cfquery>

                <cfsavecontent variable="trhead">
                    <tr class="bigbluecolor" style="text-align:center;">
                        <td width="6%">Term</td<
                    </tr>
                </cfsavecontent>
                #trhead#
                <cfloop query="getDetails">
                    <tr align="center">
                        <td width="6%">#Listfirst(TermYears,'.')# Years</td>
                    </tr>
                    <cfif getDetails.recordcount GT 6 AND getDetails.currentRow EQ 6>
                        <cfdocumentitem type="pagebreak"/>
                        #trhead#
                    </cfif>
                </cfloop>
            </table>
            </td></tr></table>
            </cfloop>
        </cfoutput>
    </cfdocumentsection>
</cfdocument>

However, it does not do the page break. It shows empty pages at the top and then it starts breaking anywhere it wants. I want my inner loop to break after 4 records and the <TH> header to repeat itself again on the start of the second page.

The trhead variable contains the code which I have wrapped with the savecontent to show it.

Can anyone explain what I am missing?

Leigh
  • 28,765
  • 10
  • 55
  • 103

1 Answers1

2

The unpredictability of the page breaks is because of this:

<cfif getDetails.recordcount GT 6 AND getDetails.currentRow EQ 6>

If getDetails has less than 6 records, that condition will never return true. Plus, if you have 12 or more records, it won't return true. I suggest this approach. First, add this to first_query:

order by type

Then build your content like this:

<cfsavecontent variable="trhead">
<tr class="bigbluecolor" style="text-align:center;">
<td width="6%">Term</td>
</tr>
</cfsavecontent>

<cfoutput query="first_query">
other content goes here
<cfif currentRow mod 6 is 0>
<cfdocumentitem type="pagebreak"/>
#trhead#    
</cfif>
</cfoutput>
Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
  • Hi @Dan: That approoach did not worked out, First it created an Empty Page and then it started with the Headers but that only on 2nd page of the pdf, if i had added trhead on after firstquery, then what i will add in the second query –  May 14 '16 at 18:35
  • Yeah, I changed it a bit. I overthought it at first. You shouldn't need more than one query based on what is in your question. – Dan Bracuk May 14 '16 at 21:44
  • i use one query but it has query of query t filter data, even i tried the order clause, it still not worked as expected –  May 14 '16 at 22:54