1
votes

I have a master query that I output that gives me a list of sports. Then I have two sub queries that give me Query1: person information on who is in each sport, and Query2: Sport books the the people from query 1 have. I am trying to output a table row as a sort of header for each sport, then additional rows for the query data. I would like to break a page after every sport so I don't have a sport description row on the bottom of a page with the rest of the data on the next.

I have tried adding in every spot imaginable, but I always end up with blank pages equaling the recordcount of the getsports query at the beginning of the document.

Here is the code I am using. I have removed the actual query data. Does anyone have any suggestions or thoughts on what I am doing wrong?

<cfquery name="getterm" datasource="DS1">
    select * from dbo.semester where current = 1
</cfquery>


<cfquery name="getsports" datasource="DS1">
    SELECT * FROM [sports]


</cfquery>

<body>

    <div id="wrap">

        <cfinclude template="header.cfm">

            <!-- header end -->

            <div class="container" style="padding-top:0px;">


                <cfdocument format="PDF" mimetype="application/pdf" orientation="landscape">


                    <table width="100%" cellspacing="0" cellpadding="0" topmargin="0" leftmargin="0" border="0" style="font-size:10px">

                        <tr>
                            <td colspan="8" bgcolor="#e3edef" style="padding-top:10px; padding-bottom:10px; padding-left:2px; font-family:Arial;" align="center">Books Not Issued -
                                <cfoutput>#yearOfSport#</h1>
                                </cfoutput>
                            </td>
                        </tr>

                        <cfoutput>
                            <cfloop query="getsports">

                                <tr>
                                    <td colspan="8" style="padding-top:10px; padding-bottom:10px; padding-left:2px; font-family:Arial;" align="center">
                                        <h1>#getsports.descr#  </h1>
                                    </td>
                                </tr>



                                <cfquery name="getbooks" datasource="DS1">
                                    ...

                                </cfquery>

                                <cfloop query="getbooks">

                                    <cfquery name="getbooks2" datasource="DS1">
                                        ...

                                    </cfquery>

                                    <tr>

                                        <td align="left" style="border-bottom: 1px solid; border-top: 1px solid; padding-top:10px;padding-bottom:10px;font-family:arial">
                                            <h4>ID</h4></td>

                                        <td align="left" style="border-bottom: 1px solid; border-top: 1px solid; padding-top:10px;padding-bottom:10px;font-family:arial">
                                            <h4>Name</h4></td>

                                        <td colspan="4" align="left" style="border-bottom: 1px solid; border-top: 1px solid; padding-top:10px;padding-bottom:10px;font-family:arial">
                                            <h4>Sport</h4></td>



                                    </tr>

                                    <tr>

                                        <td align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial; font-weight: normal;">#id#</td>

                                        <td align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial; font-weight: normal;">#nameLast#, #nameFirst#, #nameMiddle# </td>

                                        <td colspan="4" align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial; font-weight: normal;">#sport#</td>



                                    </tr>

                                    <tr>

                                        <td align="left" style="border-bottom: 1px solid ##cccccc; padding-top:10px;padding-bottom:10px;font-family:arial">Class</td>

                                        <td align="left" style="border-bottom: 1px solid ##cccccc; padding-top:10px;padding-bottom:10px;font-family:arial">ISBN</td>

                                        <td align="left" style="border-bottom: 1px solid ##cccccc; padding-top:10px;padding-bottom:10px;font-family:arial">Title</td>

                                        <td align="left" style="border-bottom: 1px solid ##cccccc; padding-top:10px;padding-bottom:10px;font-family:arial">Author</td>

                                        <td align="left" style="border-bottom: 1px solid ##cccccc; padding-top:10px;padding-bottom:10px;font-family:arial">Status</td>





                                    </tr>

                                    <cfloop query="getbooks2">
                                        <tr>

                                            <td align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial">#getbooks2.subject#</td>

                                            <td align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial">#getbooks2.ISBN#</td>

                                            <td align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial">#getbooks2.title#</td>

                                            <td align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial">#getbooks2.author#</td>

                                            <td align="left" style="padding-top:10px;padding-bottom:10px;font-family:arial">#getbooks2.status#</td>





                                        </tr>


                                    </cfloop>





                                </cfloop>

                            </cfloop>



                        </cfoutput>





                        <cfdocumentItem type="footer">
                            <table width="100%" style="font-size:10px;">



                                <tr>
                                    <td style="font-family:Arial;" align="left">
                                        <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount# - #dateformat(now(), "mm/dd/yyyy")#</cfoutput>
                                    </td>

                                </tr>

                            </table>
                        </cfdocumentItem>

            </div>

            </table>

            </cfdocument>


    </div>
    <!-- Container end -->
    <div id="push"></div>
    </div>

    <cfinclude template="footer.cfm">
</body>
2
How are you inserting a PDF page break? It doesn't look like you are using <cfdocumentitem type="pagebreak"/> anywhere. - James Moberg
Yes I had removed it for the post since anywhere I placed it produced strange results. - spacerobot
ok. I wasn't sure. WKHTMLTOPDF offers the ability to keep divs together, break after, break before, etc and seems to generate smaller, faster, better looking results. I wrote a CFTag here if you are interested. gamesover2600.tumblr.com/post/125851537339/… - James Moberg

2 Answers

0
votes

Disclaimer: I have no idea what is in those header and footer files..but the header and footer is outside of the cfdocument tag. I usually don't do that but maybe there is a reason why you do.

In order to get my breaks in looping data I add this (below) to the end of my loops, and sometimes I add a counter incase I need more surgical control.

<div style="page-break-before:always">&nbsp;</div> 

And it just works.

If you need to get some precision. I would run your page without the cf document and get the source output from the browser and start to figue what you need, don't need and where you want your breaks to occur.

Then take that and just wrap cfdocument around the raw HTML output and see if you get the desired effects.

If you data is enourmous, then grab a subset so limit your results so you can manage a smaller chuck of that report.

One other things I do for my sanity.

I use cfsavecontent and set all my HTML output to a variable and then stuff it into cfdocument so I am not mixing-it-up so to speak...

Example:

<cfsavecontent variable="buildUpReport">
<cfinclude template="header.cfm">
nested looping ad nauseum...
<div style="page-break-before:always">&nbsp;</div>
more ad nauseum looping...
<cfinclude template="footer.cfm">
</cfsavecontent>

<cfdocument localUrl="yes" 
  format="PDF" 
  mimetype="text/html" 
  marginbottom="0.15" 
  margintop="0" 
  marginright="0" 
  marginleft="0">

<cfoutput>#buildUpReport#</cfoutput>

<cfdocumentitem type="footer" evalatprint="true"> 
<table width="100%" border="0" cellpadding="0" cellspacing="0"> 
<tr><td align="center">
<cfoutput>
    #cfdocument.currentpagenumber# of 
    #cfdocument.totalpagecount# | 
    #dateformat(now(),"mm-dd-yyyy")#
</cfoutput>
</td></tr> 
</table> 
</cfdocumentitem>

</cfdocument>
0
votes

Thanks for the suggestions. I ended up including additional table tags inside my main output. Once I did that the page breaks worked correctly. I think the way I was doing it before was breaking the table structure.