Search code examples
netsuite

NetSuite Advanced PDF Total Page Number is 0


I'm creating an advanced PDF and for some reason the built in total page number is displaying as 0 on each page rendered. I'm using in in a footer macro. The current page works fine however, and correctly increments for each page, but the footer just shows 1 of 0, 2 of 0, etc. Has anyone else had this problem? (My template/code is based of a saved search displaying sales order items)

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>

<#list results as mainline>	<#-- loops through the each item that is the first in an order -->
  <#if !currentOrder?has_content || (mainline.tranid != currentOrder)>
    <#assign currentOrder = mainline.tranid/>

<head>
	<link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
	<#if .locale == "zh_CN">
		<link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
	<#elseif .locale == "zh_TW">
		<link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
	<#elseif .locale == "ja_JP">
		<link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
	<#elseif .locale == "ko_KR">
		<link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
	<#elseif .locale == "th_TH">
		<link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
	</#if>
<style type="text/css">* {
		<#if .locale == "zh_CN">
			font-family: NotoSans, NotoSansCJKsc, sans-serif;
		<#elseif .locale == "zh_TW">
			font-family: NotoSans, NotoSansCJKtc, sans-serif;
		<#elseif .locale == "ja_JP">
			font-family: NotoSans, NotoSansCJKjp, sans-serif;
		<#elseif .locale == "ko_KR">
			font-family: NotoSans, NotoSansCJKkr, sans-serif;
		<#elseif .locale == "th_TH">
			font-family: NotoSans, NotoSansThai, sans-serif;
		<#else>
			font-family: NotoSans, sans-serif;
		</#if>
		}
		table {
			font-size: 9pt;
			table-layout: fixed;
          	border-collapse: collapse;
		}
		th {
			font-weight: bold;
			font-size: 8pt;
			vertical-align: middle;
            padding: 5px 6px 3px;
            background-color: #e3e3e3;
			color: #333333;
		}
		td {
            padding: 4px 6px;
        }
		td p { align:left }
		b {
			font-weight: bold;
			color: #333333;
		}
		table.header td {
			padding: 0;
			font-size: 10pt;
		}
		table.footer td {
			padding: 0;
			font-size: 8pt;
		}
		table.itemtable th {
			padding-bottom: 5px;
			padding-top: 5px;
		}
      	table.itemtable tr {
          	border-bottom: 1px solid black;
        }
		table.itemtable tr:last-child {

		}
		table.body td {
			padding-top: 2px;
		}
		td.addressheader {
			font-size: 8pt;
			padding-top: 8px;
			padding-bottom: 2px;
		}
		td.address {
			padding-top: 0px;
		}
		span.title {
			font-size: 18pt;
          	font-weight: bold;
		}
		span.number {
			font-size: 16pt;
		}
		span.itemname {
			font-weight: bold;
			line-height: 150%;
		}
      	span.total {
          display: block;
          font-weight: bold;
		}
		hr {
			width: 100%;
			color: #d3d3d3;
			background-color: #d3d3d3;
			height: 1px;
		}
</style>
      <macrolist>
        <macro id="nlfooter">
          <table class="footer" style="width: 100%;"><tr>
            <td align="right"> <pagenumber/> of <totalpages/></td>
            </tr>
          </table>
        </macro>
        <macro id="nlheader">
          <table class="header" style="width: 100%;">
            <tr>
              <td rowspan="3"><#if companyInformation.logoUrl?length != 0><img dpi="300" src="" style="float: left; margin: 7px" /> </#if>
              </td>
              <td align="right"><span class="title">PICK TICKET</span></td>
            </tr>
            <tr>
              <td align="right">${mainline.trandate}</td>
            </tr>
            <tr>
              <td align="right" style="vertical-align: middle;"><barcode codetype="code128" showtext="true" value="${mainline.tranid}"/></td>
            </tr>
            <tr>
              <td rowspan="3" style="vertical-align: middle;  width: 28%;"><span class="nameandaddress">${companyInformation.addressText}</span></td>
            </tr>
          </table>
        </macro>
      </macrolist>
</head>

<body header="nlheader" header-height="15%" footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter" pagenumber="1">
   <table style="width: 100%;">
     <tr>
        <td class="addressheader"><b>${mainline.billaddress@label}</b></td>
        <td class="addressheader"><b>${mainline.shipaddress@label}</b></td>
        <td class="addressheader"><b>${mainline.otherrefnum@label}</b></td>
     </tr>
      <tr>
        <td class="address">${mainline.billaddress}</td>
        <td class="address">${mainline.shipaddress}</td>
        <td class="address">${mainline.otherrefnum}</td>
	  </tr>
  </table>
  <table class="body" style="width: 100%; margin-top: 10px; border: 1px">
	<tr>
        <th>${mainline.trandate@label}</th>
        <th>${mainline.shipmethod@label}</th>
        <th>${mainline.terms@label}</th>
      	<th>${mainline.salesrep@label}</th>
        <th>${mainline.custbody_entered_by@label}</th>
      </tr>
      <tr style="border-top: 1px">
        <td>${mainline.trandate}</td>
        <td>${mainline.shipmethod}</td>
        <td>${mainline.terms}</td>
        <td>${mainline.salesrep}</td>
        <td>${mainline.custbody_entered_by}</td>
      </tr>
  </table>

  <table class="itemtable" style="width: 100%; margin-top: 10px;">
    <tr style="border: 1px; border-right: 1px; border-left: 1px;">
      <th colspan="4" style="border-left: 1px;">${mainline.item@label}<br /><span style="font-weight: normal;">Item Description</span></th>
      <th>${mainline.locationnohierarchy@label}</th>
      <th>Ordered</th>
      <th>Committed</th>
      <th width="6%">${mainline.unit@label}</th>
      <th width="8%">${mainline.weight@label}</th>
      <th style="border-right: 1px;" width="11%"  align="right">${mainline.amount@label}</th>
    </tr>

<#assign totalWeight =0/>
<#assign totalAmount =0/>

    <#list results as resultitem>
<#if resultitem.item?has_content && (resultitem.tranid == mainline.tranid)>  <#-- loops through the corresponding items for the current order -->

<#-- Sums the total items of a single order -->
<#assign totalItems = 0/>
<#list results as loopitem>
  <#assign currentOrdNum = loopitem.tranid/>
  <#if currentOrdNum == resultitem.tranid>
    <#assign totalItems++/>
    </#if>
</#list>

<#-- Finds which item line number the current loop is on -->
<#if !ordNum?has_content>
  <#assign ordNum = resultitem.tranid/>
  <#assign currentItem = 1/>
<#elseif ordNum == resultitem.tranid>
  <#assign currentItem++/>
<#else>
  <#assign ordNum = resultitem.tranid/>
  <#assign currentItem = 1/>
</#if>

<#assign totalWeight += resultitem.weight/>
<#assign totalAmount += resultitem.amount/>
<#if currentItem != totalItems>
      <tr>
        <td colspan="4"><span class="itemname">${resultitem.item}</span><br />${resultitem.displayname}</td>
        <td>${resultitem.locationnohierarchy}</td>
        <td>${resultitem.quantity}</td>
        <td>${resultitem.quantitycommitted}</td>
        <td>${resultitem.unit}</td>
        <td>${resultitem.weight}&nbsp;${resultitem.weightunit}</td>
        <td  align="right">${resultitem.amount}</td>
      </tr>
<#else>
      <tr>
        <td colspan="4"><span class="itemname">${resultitem.item}</span><br />${resultitem.displayname}</td>
        <td>${resultitem.locationnohierarchy}</td>
        <td>${resultitem.quantity}</td>
        <td>${resultitem.quantitycommitted}</td>
        <td>${resultitem.unit}</td>
        <td>${resultitem.weight}&nbsp;${resultitem.weightunit}</td>
        <td align="right">${resultitem.amount}</td>
      </tr>
  	  <tr style="border-bottom: none;">
        <td colspan="7"></td>
        <td colspan="2" align="right">Total Weight:</td>
        <td align="right">${totalWeight}&nbsp;${resultitem.weightunit}</td>
  	 </tr>
  	 <tr>
        <td colspan="7"></td>
        <td colspan="2" align="right"><span style="font-weight:bold;">Grand Total:</span></td>
        <td align="right">${totalAmount?string.currency}</td>
  	</tr>
</#if>

</#if>
</#list>

</table>
</body>
<#else>
  <head>
  </head>
  <body>

  </body>
</#if>
</#list>
</pdf>


Solution

  • Unfortunately the BFO engine cannot calculate the number of pages beforehand.

    If you know how large each section of your report is you may be able to calculate the number of pages accurately and store that in a variable

    You're already doing something like what would be needed in your calculation of currentOrdNum