Динамически отображать номер страницы в cfdocument

Я могу создать PDF без проблем, но мне нужно, чтобы номер страницы PDF начинался с определенной страницы, а не с 1. Обычно я бы использовал область cfdocument, чтобы показать номер страницы, но потому что я не хочу, чтобы страница номер для начала 1 Я не могу заставить код работать. Не уверен, как лучше всего это сделать при увеличении каждой страницы. Вот код, который отлично работает:

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

Но когда я ввожу разрыв страницы, нумерация не увеличивает каждую страницу. Вот код, который не увеличивает номер каждой страницы.

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

При использовании кода, который не работает, номер страницы останется равным «10» в течение двух страниц, а затем увеличится до «11».

Любая помощь приветствуется!


person user1431633    schedule 13.11.2015    source источник


Ответы (2)


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

Также: с моим нижним колонтитулом и цифрами я делаю что-то вроде этого:

<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 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>
person Frank Tudor    schedule 13.11.2015

Это действительно сработало. В основном добавление переменной формы начальной страницы в переменную cfdocument.currentpagenumber.

<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>
person user1431633    schedule 16.11.2015