Skip to main content
Participant
August 1, 2009
Question

How to access cfdocument.currentpagenumber outside the cfdocumentitem tag

  • August 1, 2009
  • 1 reply
  • 3306 views

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"
scale=99 filename="c:\test.pdf" overwrite="yes">

<cfoutput>

<cfdocumentsection>


    <cfdocumentitem type="header">
              <cfset Page = cfdocument.currentpagenumber>
  </cfdocumentitem>


<cfdocumentitem type="footer" >
        FOOTER !!!!
</cfdocumentitem>

<table>
    <tr>
          <td>HELLO</td>
          <td> Page No : #Page#</td>
    </tr>
</table>


</cfdocumentsection>

</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"
scale=99 filename="c:\test.pdf" overwrite="yes">

<cfoutput>
<cfset Page = "">
<cfdocumentsection>


    <cfdocumentitem type="header">
              <cfset Page = cfdocument.currentpagenumber>
  </cfdocumentitem>


<cfdocumentitem type="footer" >
        FOOTER !!!!
</cfdocumentitem>

<table>
    <tr>
          <td>HELLO</td>
          <td> Page No : #Page#</td>
    </tr>
</table>


</cfdocumentsection>

</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"
scale=99 filename="c:\test.pdf" overwrite="yes">

<cfoutput>


<form>


  <input type="hidden"  id="hdnPage" />

  <cfdocumentsection>


    <cfdocumentitem type="header">
              <cfset Page = cfdocument.currentpagenumber>
    </cfdocumentitem>


    <cfdocumentitem type="footer" >
          FOOTER !!!!
    </cfdocumentitem>

    <table>
      <tr>
            <td>HELLO</td>
            <td> Page No : #Page#</td>
      </tr>
    </table>


    </cfdocumentsection>

</form>

</cfoutput>

</cfdocument>


Output : ERROR :

Variable HDNPAGE is undefined.

at line : <td> Page No : #hdnPage#</td>

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
August 2, 2009

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>

Participant
August 3, 2009

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

BKBK
Community Expert
Community Expert
August 3, 2009

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>