0
votes

I'm able to create a PDF no problem but need the page number of the PDF to begin on a certain page -- not 1. Normally I would use the cfdocument scope to show the page number but because I don't want the page number to start on 1 I can't get the code to work. Not sure how best to do this while incrementing each page. Here's the code that works fine:

<cfset theStartPageNumber = 10 />
<cfdocument format="PDF>
  <cfoutput query="getPerson">
    <cfdocumentsection>
      <cfdocumentitem type="header">
        <table>
          <tr>
            <td>My Header</td>
          </tr>
        </table>
      </cfdocumentitem>
      #getPerson.FirstName# #getPerson.LastName#
      <cfdocumentitem type="footer" evalAtPrint="true" pageNumber="#theStartPageNumber#">
        <table>
          <tr>
            <td align="center"><cfoutput>#attributes.pageNumber#</cfoutput></td>
          </tr>
        </table>
      </cfdocumentitem>
    </cfdocumentsection>
    <cfset thePageNumber ++ />
  </cfoutput>
</cfdocument>

But when I introduce a page break the numbering doesn't increment each page. Here's code that doesn't increment each page number.

<cfset theStartPageNumber = 10 />
<cfdocument format="PDF>
  <cfoutput query="getPerson">
    <cfdocumentsection>
      <cfdocumentitem type="header">
        <table>
          <tr>
            <td>My Header</td>
          </tr>
        </table>
      </cfdocumentitem>
      #getPerson.FirstName# #getPerson.LastName#
      <cfdocumentitem type="pagebreak" />
      #getPerson.Address#
      <cfdocumentitem type="pagebreak" />
      <cfdocumentitem type="footer" evalAtPrint="true" pageNumber="#theStartPageNumber#">
        <table>
          <tr>
            <td align="center"><cfoutput>#attributes.pageNumber#</cfoutput></td>
          </tr>
        </table>
      </cfdocumentitem>
    </cfdocumentsection>
    <cfset thePageNumber ++ />
  </cfoutput>
</cfdocument>

Using the code that doesn't work the page number will stay "10" for two pages then increment to "11".

Any help is appreciated!

2

2 Answers

0
votes
<cfset theStartPageNumber = 10 />
<cfdocument format="PDF>
    <cfoutput query="getPerson">
        <cfdocumentsection>
        <cfdocumentitem type="header">
            <table>
            <tr>
            <td>My Header</td>
            </tr>
            </table>
            </cfdocumentitem>
            #getPerson.FirstName# #getPerson.LastName#
            <p style='page-break-after:always;'>&nbsp;</p>
            #getPerson.Address#
            <p style='page-break-after:always;'>&nbsp;</p>
            <cfdocumentitem type="footer" evalAtPrint="true" pageNumber="#theStartPageNumber#">
            <table>
            <tr>
            <td align="center"><cfoutput>#attributes.pageNumber#</cfoutput></td>
            </tr>
            </table>
        </cfdocumentitem>
        </cfdocumentsection>
    <cfset thePageNumber ++ />
    </cfoutput>
</cfdocument>

Also: With my footer and numbers I do something like this:

<cfdocumentitem type="footer" evalatprint="true"> 
  <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
  <tr><td align="center">
  <cfoutput>
    #cfdocument.currentpagenumber# of 
    #cfdocument.totalpagecount# | 
    #dateformat(now(),"mm-dd-yyyy")#
  </cfoutput>
  </td></tr> 
  </table> 
</cfdocumentitem>

My full working example:

<cfdocument localUrl="yes" 
  format="PDF" 
  mimetype="text/html" 
  marginbottom=".0925" 
  margintop="0" 
  marginright=".1" 
  marginleft=".1">
  <cfoutput>
      test 
      <p style='page-break-after:always;'>&nbsp;</p>
      test
      <p style='page-break-after:always;'>&nbsp;</p>
      test
      <p style='page-break-after:always;'>&nbsp;</p>
</cfoutput>
<cfdocumentitem type="footer" evalatprint="true"> 
  <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
  <tr><td align="center">
  <cfoutput>
    #cfdocument.currentpagenumber# of 
    #cfdocument.totalpagecount# | 
    #dateformat(now(),"mm-dd-yyyy")#
  </cfoutput>
  </td></tr> 
  </table> 
</cfdocumentitem>
</cfdocument>
0
votes

This actually ended up working. Basically adding the start page form variable to the cfdocument.currentpagenumber variable.

<cfdocumentitem type="footer" evalAtPrint="true" no="#thePageNumber#">
  <span style="border-top:1px solid black;display:block;">&nbsp;</span>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-bottom:50px;">
      <tr>
        <td align="left"><font face="Tahoma" color="black"><strong>High Desert Corridor</strong><br/>Street address<br/>City, ST 55555</font></td>
        <td align="center"><cfoutput>#evaluate(attributes.no + cfdocument.currentpagenumber - 1)#</cfoutput></td>
        <td align="right"><font face="Tahoma" color="black">Phone: 555.555.5555<br/>Fax: 555.555.5555<br/>Email: [email protected]</font></td>
      </tr>
    </table>
</cfdocumentitem>