There is syntax in the Advanced PDF template engine that's something like:
<#iftrue>
<table></table>
<#else>
<table></table>
I would recommend finding a PDF which does something similar to what you want and copy/edit the code to work for you.
However, with a bit of practice, I think you'll find it much easier to create PDF's with JavaScript and XML. I'm doing this from the top of my head, so some of it may be off. If you need help, or I've made an error, please don't hesitate to reach out.
The setup is a User Event, a Suitelet, and an XML file.
- User Event Script to display a button in view mode that opens a Suitelet when clicked:
/**
* @NScriptType UserEvent
* @NApiVersion 2.0 // 2.1 if you can
*/
define(["N/anyLibrariesYouNeed"), function(anyLibrariesYouNeed) {
function beforeLoad(context){
if (context.type === "view") {
context.form.addButton({
id: "custpage_print_pdf",
label: "Print PDF",
functionName: 'window.open("link_to_suitelet")'
}
return {beforeLoad: beforeLoad}
})
- Suitelet which is opened from the above User Event, and replaces placeholder text in the XML file with conditional text:
/**
* @NScriptType Suitelet
* @NApiVersion 2.0 // 2.1 if you can
*/
define(["N/file", "N/search", "N/anyLibrariesYouNeed"], function(file, search, anyLibrariesYouNeed) {
function onRequest(context) {
// Load the PDF, which is just an XML file
var myPDF = file.load("path_to_your PDF").getContents();
// Load the search
var mySearch = search.load({id: "mySearchId"});
// Do some stuff with the results ...
var myResults = [];
mySearch.run.each(function(result){
// ... like generate a </table> or group results with Lodash
})
//Just make sure all the placeholder text in your XML (PDF) file is replaced. If it's not do ...
myPDF = myPDF.replace("Placeholder", "With this");
//Finally, render the PDF from XML using the bigfaceless engine provided by NetSuite. The setup for bigfaceless is in the XML file.
context.response.renderPdf(myPDF);
}
return {onRequest: onRequest}
})
- Placeholder XML file which is rendered as a PDF using
context.response.renderPdf(myPDF)
//big_face_less_tag_goes_here and something like DOCTYPE XML
<pdf>
<head>
<style>
table tr th td {
border: 1px solid black
}
</style>
<body>
Placeholder
</body>
</pdf>
Hope that helps. If you need help, just holler!