在cfdocument中动态显示页码

时间:2015-11-13 02:54:37

标签: pdf-generation coldfusion-10 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”。

感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

这实际上最终起作用了。基本上将起始页面表单变量添加到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: info@domain.com</font></td>
      </tr>
    </table>
</cfdocumentitem>
相关问题