Learn how to combine multiple advanced PDFs into one

Introduction

What if you have multiple advanced PDFs and need to combine them into one? You could just combine them into one advanced PDF to solve the problem. For one of my clients, this wasn’t going to work as they needed to be able to print specific PDFs based on specific criteria. For example, if the sales order included a specific item then a specific set of advanced PDFs should be printed. This article will detail how to merge multiple advanced PDFs into one document using a Suitelet.

My example will use the sales order record. I’ve created three different advanced PDFs for the sales order, as you can see below.

 

 

To see the internal IDs of these advanced PDFs, you can hover over the edit button, and then you will see the ID in the URL. You can also edit them and see the ID in the URL.

 

 

Modify the code below to use the internal IDs for the advanced PDFs you want to print.

 

/**
 *@NApiVersion 2.1
 *@NScriptType Suitelet
 */
define(['N/record','N/render'],
    (record, render) => {

	onRequest = (context) => {
        // templates to render - Change these IDs to the IDs of the templates you want to render
        const templates = [102, 107, 108];
        const renderer = render.create();
        // attach the sales order record
        const salesOrderRecord = record.load({
            type: record.Type.SALES_ORDER,
            id: 22326
        });
        renderer.addRecord('record', salesOrderRecord);
        // render each template and put in array
        let salesOrderPDFArray = [];
        for (let i = 0; i < templates.length; i++) {
            renderer.setTemplateById(templates[i]);
            var soasString = renderer.renderAsString();
            // remove the first line
            soasString = soasString.replace('<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">', '');
            salesOrderPDFArray.push(soasString);
        }

        let finalXML = '<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">';
        finalXML += '<pdfset>' + salesOrderPDFArray.join('') + '</pdfset>';
        // render final xml
        context.response.renderPdf(finalXML);
    }

    return {onRequest};
});

Add and deploy the script.  If needed, reference my article, “Quick Guide to Adding and Deploying a Script in NetSuite”.

To use this Suitelet, you would create a user event script to show a button, “Print Sales Order”, on the sales order. Clicking the button would call the Suitelet, which would render the PDF.

Here are the three pages that were printed, forming the combined PDF.

 

 

 

 

Conclusion

Advanced PDFs are powerful but can be tricky. Do you need help with an Advanced PDF customization? If so, please contact Suite Tooth Consulting here to set up a free consultation.

If you liked this article, please sign up for my newsletter to get these delivered to your inbox here.

Follow on
Jaime Requena Chief Executive Officer

Jaime Requena is a seasoned NetSuite Consultant and Solutions Architect, known for delivering WHITE GLOVE service to businesses. With 15+ years of experience and 3x certifications in ERP, Developer, and Admin, Jaime specializes in highly customized NetSuite accounts, transforming operations for 200+ satisfied customers all across the globe.

Get Connected

How can we help?


    Stay in the loop with Suite Tooth Consulting!

    We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!

    Global Client Satisfaction

    Client Testimonials

    It’s Been 4+ Years Now And We Have Worked With Hundreds Of Clients, Building Our Way To The Top, One Happy Client After Another! Their Voices Of Satisfaction Serve As A Testament To Our Success –