I am creating an advanced PDF attached to a saved ...
# advancedpdf
m
I am creating an advanced PDF attached to a saved search of items. I want to print each item on 1/4 of the page so we can print item labels from them. But I am having trouble finding a way to do this. Everything I have tried so far has generated an unexpected error.
n
You're going to need to supply more detail of what you've done so far. Perhaps drop the code you've tried in chat for people to be able to troubleshoot for you too.
m
This is what I have that works. As it is now, it just prints each item one after another.
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">table { font-size: 9pt; table-layout: fixed; width: 100%; }
th { font-weight: bold; font-size: 8pt; vertical-align: middle; padding: 5px 6px 3px; background-color: #e3e3e3; color: #333333; padding-bottom: 10px; padding-top: 10px; }
td { padding: 4px 6px; }
b { font-weight: bold; color: #333333; }
div { width: 50%; height: 50%; float: left; }
</style>
</head>
<body padding="0.5in 0.5in 0.5in 0.5in" size="Letter"> <!-- Letter A4-->
    <table><#list results as result><#if result_index == 0>
</#if>

      <tr>
	<td><barcode bar-width="0.5" codetype="code128" showtext="true" value="${result.itemid}" /></td>
      </tr>
      <tr  >
	<td><barcode bar-width="0.5" codetype="code128" showtext="true" value="${result.custitem90}" /></td>
      </tr>
	<tr  >
	<td>Cartridge, Toner ${result.manufacturer}</td>
      </tr>
      <tr  >
	<td>${result.displayname}</td>
        </tr>
      <tr >
	<td>${result.quantity}: Each</td>
        </tr>
      <tr  >
      <td>Stage Code: 0G4A2</td>
        </tr>
      <tr  >
	<td>Contract Number: ${result.pricelevel}</td>
	</tr>
      
	</#list>
      
  </table>
</body>
</pdf>
I've been trying different approaches using <div> and CSS but its either not formatting as I thought or it is generating unexpected errors. I am wondering if this will have to be a script solution
n
You shouldn't need to script anything. You are iterating the items sublist outputting the data as a table. You need to either avoid using a table or use CSS in the table, maybe setting row height or some other sensible property. Unfortunately whilst I'm pretty good with Adv PDF's generally I'm awful using CSS in FreeMarker templates. I imagine some fine soul will be able to better advise though. Maybe try with SPANs if DIVs didn't work?
p
It can be very hard to wing a complete layout, a skilled frontend developer could likely provide a shell with minimal effort, adding the Freemarker from there is likely trivial - failing that you can try your luck with a wysiwig editor and see if the output html/css can help you progress
n
Just be warned if you flip-flop between the WYSIWYG and source editor it can do weird things,
p
Yes I actually meant an external one just for the html frame - but yea maybe give the built-in one a try. I would say you should only do view source once in that though, after that it may already be broken sadly.
m
I got it pretty close to what Im looking for, but cant seem to figure out how to get the box heights to be correct. The width is correct, but the heights are not. Any pointers are welcome
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="0.5in 0.5in 0.5in 0.5in" size="Letter">
    <#list results as result>
      <table border="1" cellpadding="1" cellspacing="1" style="width:50%; height:50%; float:left; ">
        <tr><td>
      <barcode bar-width="1" codetype="code128" showtext="true" value="${result.itemid}" />
        </td></tr>
      <tr><td>
	<barcode bar-width="1" codetype="code128" showtext="true" value="${result.custitem90}" />
        </td></tr>
      <tr><td>
     Cartridge, Toner ${result.manufacturer}
        </td></tr>
      <tr><td>
	${result.displayname}
      </td></tr>
      <tr><td>
	${result.quantity}: Each
      </td></tr>
     <tr><td>
      Stage Code: 0G4A2
        </td></tr>
      <tr><td>
	Contract Number: ${result.pricelevel}
       </td></tr>
      </table>
      </#list>

</body>
</pdf>
d
I got it working by wrapping it in another
<#list ...>
and setting the height in inches. Setting the height of the table as a percentage doesn't work. I think this is because there's no concept of the table's "parent container" having a height when the table tries to calculate what it's height should be. As we know this is a Letter sized page with
0.5in
borders, we can set the table height to
5in
(letter = 11 inch tall). I found that I didn't actually need to set the width. And I pulled the float out of the css style into it's own attribute. Don't need to set
display="inline"
as that's implicitly set by
float="left"
and here are some screenshots (thumbnails) of the resulting print. The first is what I got with your code, the second is after setting
height:5in
, and the last is after wrapping it in the
<#list results?chunk(4) ...>
🙌🏻 1
apologies for the spam comment+delete before. Slack classed my HTML snippet as a binary file and refused to display it in-app. Instead I've uploaded it as XML
m
fantastic! thank you so much. I wouldnt have thought to wrap it in another list. I will have to look into more about how the #list works