• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to access cfdocument.currentpagenumber outside the cfdocumentitem tag

New Here ,
Jul 31, 2009 Jul 31, 2009

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"
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>

TOPICS
Advanced techniques

Views

3.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 02, 2009 Aug 02, 2009

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 02, 2009 Aug 02, 2009

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 03, 2009 Aug 03, 2009

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation