Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
804 views
in Technique[技术] by (71.8m points)

pdf - COLDFUSION: cfdocument and forcing a pagebreak

I am creating a dynamic PDF in ColdFusion and having an issue with "pagebreak". The page in question could have 1 record, or up to 60+ records. Each record is displayed in 2 rows of a table. Some of the returned records are being split between pages (first row is at the end of page one, the second row is the top row of the next).

A sample record in displayed HTML:

<tr>
  <td>Title</td><td>Price</td>
  <td colspan="2">Description</td>
</tr>

Per client request, I am trying to display =< 9 records per page.

Here is a dumbed down sample of something I have tried:

<cfdocument format="PDF">
<cfoutput query = "sqllookup">
<cfset loopcount = loopcount + 1>
<cfif loopcount EQ '9'>
 <cfdocumentitem type="pagebreak" />
<cfelse>
<tr>
  <td>#Title#</td><td>#Price#</td>
  <td colspan="2">#Description#</td>
</tr>
</cfif>
</cfoutput>
</cfdocument>

This does not work, (it only hides the 9th record). I have tried several different ideas, and I am currently stumped. Am I over looking something?

Thanks in advance.

ColdFusion MX 7. (I also ran the hot fix for text cut-off issue. http://kb2.adobe.com/cps/402/kb402093.html)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are hiding the 9th record because you are choosing between displaying it and showing it:

if 9th record
    break page
else
    show record
end if

What you want is more like:

<cfoutput query = "sqllookup">
    <!--- this is the 9th row, because 9 mod 9 is 0 --->
    <cfif not sqllookup.currentrow mod 9>
        <cfdocumentitem type="pagebreak" />
    </cfif>
    <tr>
        <td>#Title#</td><td>#Price#</td>
        <td colspan="2">#Description#</td>
    </tr>
</cfoutput>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...