Search code examples
pdfnetsuite

Merge PDF into netsuite?


I'm a netsuite developer/admin, I want to know if it's possible implement PDF Merge Tool into my netsuite via script or workflow to merge the selected invoice PDFs of my saved search into a single PDF document. The script or workflow can use a third-party PDF merge tool, such as the one provided by Smallpdf or another similar tool. If Yes how ?

I tried multiple different code first I was blocked by scripts since they don't work on saved search and I can't create a button "Print" to trigger that said script nore Workflow so I'm little bit confused how I can handle this.

Update: I tried to directly add in my netsuite saved search a HTML formula:

'<a href="https://smallpdf.com/merge-pdf#r=organize-merge&print=' ||
  {print}.map(function(printValue) {
    return 'print[]=' + printValue;
  }).join('&') ||
  '" target="_blank"><input type="button" value="PDF Merge" /></a>'

For it to take the value of the invoice print and directly transfer that value to the website but it's not working but I think their is something to be done with this.


Solution

  • You won't be able to print multiple records to one document directly from the native saved search page.

    Here's one way to approach this:

    1. Create a Suitelet with a GET function which makes a search and lists the results.
    2. In the result list, add a checkbox for the selected records.
    3. In the POST function (which is called when you click Submit (from serverWidget.addSubmitButton())), parse the data which is passed in from NetSuite, to determine the IDs of all the records.
    4. Use render.transaction from the N/render module to generate PDFs of each invoice.
    5. Save them as files in the document cabinet using N/file. Set the "Available Without Login" (isonline) option for these files as true. Save the URLs for all the files into an array.
    6. Generate the merged file by iterating your array of URLs, adding each as a <pdf src and using pdfset to group the PDFs together:
    <?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
    <pdfset>
    <pdf src=*link to first file cabinet document*></pdf>
    <pdf src=*link to second file cabinet document*></pdf>
    ...
    </pdfset>
    

    You can then delete the individual PDF files.

    Another approach would be use the native "Print Checks and Forms" tool at Transactions > Management > Print Checks and Forms. Click on the link for Invoices, click the Customize button to add any filters you're interested in and optionally select Allow Reprinting - then click Print. This would, of course, be a lot easier unless you need some flexibility or functionality it can't provide.