Anyone know of any way to create *modern* PDFs in ...
# suitescript
e
Anyone know of any way to create modern PDFs in NetSuite? Not talking about the Advanced PDFs as they have MANY limitations due to BFO But maybe a Bundle/SuiteApp that converts HTML to PDF and allows you to use HTML5/CSS3?
👀 1
e
This (using HTML5+CSS3 to generate a PDF) is a huge pain even outside of NetSuite, so I'd be curious to see if anyone has managed it inside of NS as well.
b
easiest is integrating with an external api that renders the pdf based on the html5/css3
i was thinking of making a blog post about it
👍🏻 1
👍 1
e
@borncorp Something like https://html2pdf.app/ ?
b
yeah, there are several; I havent used that one
e
I can half accomplish my goal using
html2pdf.js
(the client side library) If I use that in a Suitelet, I can get the base64 encoded string of the PDF and then send that to the backend of the Suitelet and use
file.create
to create the file. But I was trying to figure out a fully backend solution e.g. Create a Print button on an Invoice that just sends the Transaction ID (and maybe a template id) to a suitelet, the suitelet creates a HTML/CSS string, I use a library (or API) to convert the HTML string into a base 64 encoded string, create the file and render the PDF to the user
@borncorp Have you used any of them? / Do you have any recommendations?
s
It's not HTML, but I have done a POC with https://pdf-lib.js.org in server-side suitescript
I didn't test it for this, but since it supports editing PDFs, perhaps you can author the PDF natively then edit (rather than the indirect approach transforming html)
e
@Shawn Talbert will definitely check this out
s
let us know how it goes!
b
I've used PDF-lib.js and it's very limited, perhaps even more limited than BFO. Also runs into errors oftenly, not sure if perhaps the operations are intensive to run using Suitescript. Simple stuff works though.
I used PDFLayer.com, the API was simple enough, but I didn't want to have to pay for it, I then was experimenting with a Google Cloud Function since it runs node.js on demand, but I didn't continue working on it. I didn't know more people were interested in this.
Copy code
var htmlTemplate=file.load({id: 5854 });
    //var htmlTemplate = "<html><header><title>This is title</title></header><body>Hello world</body></html>";
    
    var htmlString = htmlTemplate.getContents();
    
    
    var urlTemplate = '<http://api.pdflayer.com/api/convert>'
                    + '?access_key=' + PDF_LAYER_ACCESS_KEY
                    + '&use_print_media=1'
    
    var response = <http://http.post|http.post>({
        url: urlTemplate,
        body: 'document_html=' + encodeURIComponent(htmlString),
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    });
    
    var base64PDF = response.body;
    var fileObj = file.create({
        name: 'result.pdf',
        fileType: file.Type.PDF,
        contents: base64PDF,
        description: 'This is a PDF saved from PDFLayer.com.',
        folder: 695,
        isOnline: true
    });
    
    var fileId = fileObj.save();
e
🤔 That looks promising
I'll kick around some of these options. This is not really a NEED right now, but more of a want, so it may be a while before I get around to it. But I'll circle back with any results
f
Take a look at ReportLab for Python or Puppeteer for Node.js. You can run either in a Lambda. If you use Puppeteer, you can repurpose a lot of your existing templates with minimal effort.