I have an advanced PDF template that currently loo...
# advancedpdf
m
I have an advanced PDF template that currently loops through items from a search and shows 4 items per page. I am trying to get it to print each item based on the quantity (if there is quantity 3, print it 3 times) From what I have found, I think I can do it with <#list record.item as item> <#list 1..item.quantity as i> but I am not sure how to implement it in this situation. Any help, pointers, or documentation is appreciated
Copy code
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<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">
body{ height:100%; margin: 0; padding: 0; }
html { height: 100%; margin: 0; padding: 0;}
      
</style>
</head>
<body padding="1in 0.45in 0.5in 0.75in" size="Letter"> <!-- Padding top right bottom left -->
  <#list results?chunk(4) as page>
    <#list page as result>	
      <table border="1" margin-right="0.2in" cellpadding="1" cellspacing="10" style=" height:4.5in; width:3.5in;" float="left">          
       <tr><td align="right">
      <barcode bar-width="1" codetype="code128" showtext="true" value="${result.custcol_gsaitemreqnumber}XXX" />
      </td></tr>             
       <#if result.custitem90?has_content>
      <tr><td align="right">
	<barcode bar-width="1" codetype="code128" showtext="true" value="${result.custitem90}" />
        </td></tr>
         <#else>
         <tr><td align="right">
	<barcode bar-width="1" codetype="code128" showtext="true" value="${result.itemid}" />
        </td></tr>        
        </#if> 
      <tr><td align="right">
     Cartridge, Toner ${result.manufacturer}
        </td></tr>
      <tr><td align="right">
	${result.displayname}
      </td></tr>
      <tr><td align="right">
	${result.quantity}: Each
      </td></tr>
     <tr><td align="right">
      Cage Code: 0G4A2
        </td></tr>
      <tr><td align="right">
	Contract Number: ${result.pricelevel}
       </td></tr>
      </table>
      </#list>
    <pbr />
      </#list>
</body>
</pdf>
d
maybe something like:
Copy code
<#assign qtycount = 0>
<#list results as result>
  <#list 1..result.quantity>
    <#assign qtycount++>
    <#-- do actual printing of result content here -->
    <#if qtycount % 4 == 0>
      <pbr> <#-- page break -->
    </#if>
  </#list>
</#list>
🙌 1
m
thank you. I am trying this out but am getting an error saying that <#list 1..result.quantity> #list must have either "as loopVar" parameter or nested #items that belongs to it. When I add "as anyVariable" I can hit save but then it goes into an infinite loop trying to validate it. Do you have any suggestions on where to look for documentation on how the <#list 1..result.quantity> works? I think I understand how it works on a surface level but it seems that I am missing something.
d
I typo'd my example, definitely should be
<#list 1..result.quantity as i>
You can read about it in the freemarker docs: list, else, items, sep, break, continue - Apache FreeMarker Manual Basically in freemarker the notation
x..y
is shorthand for creating a sequence of integers between x and y (inclusive). so
<#list 1..5 as i>${i}</#list>
would print
12345
you can also do this in reverse (so
5..1
would output
54321
)
To confirm, have you tried something like
<#list 1..result.quantity as i>
?