ANS-1106 · SUITESCRIPT DEVELOPMENT

How to Merge Multiple PDF Documents in NetSuite Using XML and BFO?

NetSuite users can combine several PDF files into a single document by leveraging XML structures and the BFO Report Generator.

Short answer

NetSuite offers two primary methods to merge multiple PDF documents: either by combining XML strings directly before PDF generation or by generating individual PDFs, saving them to the file cabinet, and then merging them using a <pdfset> XML structure with xmlToPDF.

Scenario

NetSuite users often need to combine multiple PDF documents, such as invoices, purchase orders, or custom reports, into a single consolidated file. This requirement typically arises when presenting comprehensive information or streamlining document delivery.

Solution

NetSuite provides two primary methods for merging multiple PDF documents, both leveraging the xmlToPDF function:

  1. Merging XML Strings Directly:

    This approach involves combining all XML strings generated from a template renderer. For SuiteScript 2.x, this would typically involve functions like render.create() and TemplateRenderer.renderAsString(). For SuiteScript 1.0, the function nlapiCreateTemplateRenderer.renderToString is used. These individual XML outputs are then prepended with and appended with to form a single XML string before being passed to xmlToPDF.

  2. Merging Pre-Generated PDFs from File Cabinet:

    This method requires generating each PDF individually using xmlToPDF and saving them to the NetSuite file cabinet. Once all PDFs are stored, xmlToPDF is called again, this time feeding it an XML string that references the URLs of the saved PDF files. The correct XML structure for this is as follows:

xml
    <pdfset>
    <pdf src="file_cabinet_url_of_first_pdf"/>
    <pdf src="file_cabinet_url_of_second_pdf"/>
    <pdf src="file_cabinet_url_of_third_pdf"/>
    </pdfset>

Ensure that the src attribute correctly points to the file cabinet URL of each respective PDF.

For comprehensive documentation on BFO Report Generator tags and their usage, consult the official BFO user guide: http://bfo.com/products/report/docs/userguide.pdf

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant