3 Replies Latest reply on Aug 3, 2009 3:18 PM by BKBK

    How to access cfdocument.currentpagenumber outside the cfdocumentitem tag

    Renu Deshpande

      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>

        • 1. Re: How to access cfdocument.currentpagenumber outside the cfdocumentitem tag
          BKBK Adobe Community Professional & MVP

          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>

          • 2. Re: How to access cfdocument.currentpagenumber outside the cfdocumentitem tag
            Renu Deshpande Level 1

            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

            • 3. Re: How to access cfdocument.currentpagenumber outside the cfdocumentitem tag
              BKBK Adobe Community Professional & MVP

              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>