coldfusioncoldfusion-9cfdocument

Cfdocumentitem pagebreak during loop gives extra blank page


I am using CF9, and ColdBox. What I am doing is looping through a query, and assigning a page break at the end using cfdocumentitem pagebreak. However, it always gives me an extra blank page at the end. It's pretty much driving me crazy, so I defer to expert advice.

<cfdocument format="PDF"  overwrite="Yes" localUrl="yes" pageType = "letter">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
    <cfquery name="Receipts" dbtype="query">
        SELECT distinct id_number
        FROM rc.RC1
    </cfquery>

    <cfoutput>
    <cfloop query="Receipts">
        <!--- removed for brevity --->
        <cfdocumentitem type="pagebreak" />
    </cfloop>
    </cfoutput>
</body>
</html>
</cfdocument>

Solution

  • If you don't want to display the pagebreak after the last item in the loop then you have to explicitly say that. If the current row of the query is not the last row in the query then display the page break.

    <cfloop query="Receipts">
      <cfif Receipts.currentRow NEQ Receipts.recordCount>
        <cfdocumentitem type="pagebreak" />
      </cfif>
    </cfloop>