0
votes

In NetSuite, some of our Products have MSDS documentation (in the form of PDF files) attached to the record via a Custom Item Field whose "Type" is set to Document. When printing Invoices, we would like to automatically print out any associated MSDS PDF files as well. Is this possible with SuiteScript or any of the other services that extend NetSuite?

(For what it's worth, we know there's an option for printing MSDS documents as part of a Bill of Materials, but printing MSDS docs along with an Invoice doesn't seem to native to NetSuite.)

2
You mean you want to print the Pdf document embedded in the PDF of the record or you want to print PDF as a separate file?prasun
Essentially, I need to print an invoice, iterate through each item on the invoice, and print any PDFs that are associated with those items. It doesn't matter if the invoice and associated documents are merged into a single file or printed in succession. The only requirement is that the PDFs relevant to the Invoice Items are printed along with the Invoice in some way. Thanks, in advance, for any help you can offer!tedxas
When you print a record in Netsuite you get a pdf or html, do you mean that you want to get pdf mailed or open in browser tabs??prasun
Standard behavior allows a user to generate an Invoice in PDF format for printing later. We would like for the Invoice PDF to have all of the associated MSDS documents merged into it.tedxas

2 Answers

1
votes

Luckily you can probably do this with Advanced HTML/PDF templates. Your MSDS needs to be in a folder that is accessible to the person doing the printing.

Check out http://bfo.com/products/report/docs/tags/tags/pdfset.html Then your normal invoice would be inside a pdf element something like:

<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdfset>
<pdf> <!-- normal invoice here -->
<head>
...
</pdf>

<#assign msdsSeen='' /> <!-- if can use javascript hash as a set then great. othewise use string -->
<#list record.item as item>
<#if item.custcol_msds_link?has_content><!-- needs to be sourced from item -->
<#assign msdsKey='_'+item.custcol_msds_link+'_' />
<#if msdsSeen?indexOf(msdsKey) == -1>
<#assign msdsSeen=msdsSeen + msdsKey />
<pdf src="${item.custcol_msds_link}" />
</#if> <!-- msds not linked -->
</#if> <!-- has msds -->
</#list>
1
votes

If PDFSET does not works well, you can do the merging using a client application in a server side language like (eg- Java,Node.js).

Write a RESTlet to grab PDFs of record and the attached PDFs. RESTlet will return the PDF in base64 format.

Next, step would be to fetch the PDFs in client application and decode it from base64 and create PDFs. Then using process APIs in client application merge the PDFs using pdftk

PDFtk is a command line tool so you can fairly invoke it using process APIs in your programming language

Below is an example of process APIs in Node.js

var spawn = require('child_process').spawn;
var pdftk = spawn('pdftk', "invoice.pdf attachment.pdf cat output out1.pdf".split(" "));

    pdftk.on('close', function (code) {
        if(code !==0){
            return console.log('Failed PDF with code: ' + code);
        }
        return console.log ('All good');
    });

Below is a Java snippet of Process APIs

Process process = new ProcessBuilder("pdftk","invoice.pdf", "attachment.pdf", "cat", "output", "merged.pdf").start();
                errorStream = process.getErrorStream();
                errorMessage = readInputStream(errorStream);
                if(process.exitValue() == 0) {
                    trace("successful :)");
                }