Skip navigation
Renu Deshpande
Currently Being Moderated

How to access cfdocument.currentpagenumber outside the cfdocumentitem tag

Jul 31, 2009 9:47 PM

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>

 
Replies
  • Currently Being Moderated
    Aug 2, 2009 10:58 AM   in reply to Renu Deshpande

    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>

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2009 3:18 PM   in reply to Renu Deshpande

    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>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points