Copy link to clipboard
Copied
Hi all
Can anybody help me with this.
I want to access cfdocument.currentpagenumber outside the cfdocumentitem tag. I tried the following ways :
1)
<cfdocument format="pdf" orientation="landscape" unit="cm" margintop="4.0" marginbottom="2.0" marginleft="2.2" marginright="2.2" <cfoutput>
<table>
</cfoutput> </cfdocument> |
Output :
Variable PAGE is undefined. |
At Line : <td> Page No : #Page#</td>
2)
<cfdocument format="pdf" orientation="landscape" unit="cm" margintop="4.0" marginbottom="2.0" marginleft="2.2" marginright="2.2" <cfoutput>
<table>
</cfoutput> </cfdocument> |
Output :
No Error on PDF , but value of Page is blank. I do not get the value of cfdocument.currentpagenumber in Page.
3)
<cfdocument format="pdf" orientation="landscape" unit="cm" margintop="4.0" marginbottom="2.0" marginleft="2.2" marginright="2.2" <cfoutput>
<cfdocumentsection>
<table>
</form> </cfoutput> </cfdocument> |
Output : ERROR :
at line : <td> Page No : #hdnPage#</td>
Copy link to clipboard
Copied
The way I read it, the variables cfdocument.currentpagenumber and cfdocument.totalpagecount are read-only. You may not assign variables to them as you do with page = cfdocument.currentpagenumber. Also, their scope of definition is restricted to within the cfdocumentitem tag.
You can easily define your own page numbers. Just make sure your variable for page-number increments in each subsequent cfdocumentitem tag of type page-break or footer. An example follows.
<cfdocument format="PDF">
<cfoutput>
<cfset Page = 1>
<cfdocumentsection>
<cfdocumentitem type="header">
HEADER <cfoutput>#cfdocument.currentpagenumber#</cfoutput>
</cfdocumentitem>
<table>
<tr>
<td>HELLO</td>
<td> Page No : #page#</td>
</tr>
</table>
<cfdocumentitem type="footer" >
FOOTER #page# !!!!
<cfset page = page+1>
</cfdocumentitem>
</cfdocumentsection>
<cfdocumentsection>
<cfdocumentitem type="header">
HEADER <cfoutput>#cfdocument.currentpagenumber#</cfoutput>
</cfdocumentitem>
<table>
<tr>
<td>HELLO</td>
<td> Page No : #page#</td>
</tr>
</table>
<cfdocumentitem type="footer" >
FOOTER #page# !!!!
</cfdocumentitem>
</cfdocumentsection>
</cfoutput>
</cfdocument>
Copy link to clipboard
Copied
Hi BKBK,
Thanks for your inputs.
I am able to access the variable Page outside the <cfdocumentitem> scope , but the value doesnt change on each page.
<cfdocument format="PDF">
<cfoutput>
<cfset Page = 1>
<cfdocumentsection>
<cfdocumentitem type="header">
HEADER <cfoutput>#cfdocument.currentpagenumber#</cfoutput>
</cfdocumentitem>
<table>
<cfloop index = "i" from="1" to="500">
<tr>
<td>HELLO</td>
<td> Page No : #Page#</td>
</tr>
</cfloop>
</table>
<cfdocumentitem type="footer" >
FOOTER
<cfset page = page+1>
</cfdocumentitem>
</cfdocumentsection>
Current Output :
HEADER 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
FOOTER
HEADER 2
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
FOOTER
The desired output is :
HEADER 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
Hello Page No 1
FOOTER
HEADER 2
Hello Page No 2
Hello Page No 2
Hello Page No 2
Hello Page No 2
Hello Page No 2
Hello Page No 2
FOOTER
How can I get the value of variable Page which has been updated in <cfdocument item type = "footer"> tag ??
Thanks in advance
Copy link to clipboard
Copied
The page-increment must of course be in the loop. That is, the code should end like this:
</table>
<cfdocumentitem type="footer" >
FOOTER
<cfset page = page+1>
</cfdocumentitem>
</cfloop>
</cfdocumentsection>