While working on NetSuite implementations you may have come across situations where you had to generate a PDF report from a particular record by appending multiple PDF documents together.
I recently encountered this requirement while trying to merge Customer statements and invoices.
The solution:
- First create the single PDF’s and save it to the file cabinet,
- Make sure the pdf file (in the file cabinet) is set to “Available without login”
- Get an array of all the newly created PDF’s,
- Iterate over the array and insert each one separately into a PDF tag,
- Append them all into one pdf document report using the PDFSET tag provided by BFO for appending PDFs.
(see the code below).
var arrayWithUrls = ["/core/media/media.nl?id=theid&c=myaccoutn&h=1122&_xt=.pdf", "/core/media/media.nl?id=theid&c=myaccount&h=2233&_xt=.pdf"]var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n"xml += "<pdfset>"xml += "<pdf>\n<body font-size=\"12\">\n<h2>Merged PDF</h2>\n"xml += "<p></p>"xml += "Document body"xml += "</body>\n</pdf>"
arrayWithUrls.map(function (x) {var cleanPdfURL = mxml.escape({xmlText: x});xml += '<pdf src="https://system.netsuite.com' + cleanPdfURL + '"></pdf>'})xml += "</pdfset>"