How To Create A PDF By Clicking A Button Using Suitescript

First, I will add a button in ‘BeforeLoad’ event of ‘user-event script’.

 Here, nlapiResolveURL(type, identifier, id, displayMode) API is used to create a URL on-the-fly by passing URL parameters from within SuiteScript.

 nlobjForm.addButton(name, label, script) is used to create a button. nlapiLogExecution(type, title, details) logs an entry in the  script Execution Log subtab, which appears on the Script Deployment page.

function UserEventAddButton() {
        var internalId = nlapiGetRecordId();

        if (internalId != null) {
            var createPdfUrl = nlapiResolveURL('SUITELET', 'customscript_suitelet_transferorderpdf', 'customdeploy_transferorderpdf', false);
            createPdfUrl += '&id=' + internalId;

            //---add a button and call suitelet on click that button and it will open a new window
            var addButton = form.addButton('custpage_addButton', 'Print', "window.open('" + createPdfUrl + "');");
        }
        else {
            nlapiLogExecution('DEBUG', 'Error', 'Internaal id of the record is null');
        }

Then, on button click, a ‘suitelet script’ will be called to create a pdf.

nlapiXMLToPDF(xmlstring) API passes XML to the BFO tag library (which is stored by NetSuite),

and returns a PDF nlobjFile object.

setContentType(type, name, disposition) sets the content type for the custom responses (and an optional file name for binary output).

write(output) write information (text/xml/html) to the response.

function SuiteletPdfGeneration(request, response)
{
                var xml = "\n\n";
                xml += "";
                xml += "
"; xml += ""; xml +="HELLO"; //Add values(in string format) what you want to show in pdf xml += ""; var file = nlapiXMLToPDF(xml); response.setContentType('PDF', 'Print.pdf ', 'inline'); response.write(file.getValue()); }
150 150 Burnignorance | Where Minds Meet And Sparks Fly!