Use JS to write HTML Files, put these on a webserver that runs on localhost (or some webserver where you can upload files to). Call Google Chrome in headless mode to convert HTML to PDF:
URL=https://localhost:8000/myfile-created-from-js.html # some HTML file
OUTFILE=myfile-created-from-js.pdf # PDF file
google-chrome --disable-gpu --headless $URL --print-to-pdf # HTML 2 PDF
mv output.pdf $OUTFILE # rename PDF
I think that initially the file will always be called output.pdf
, so you have to rename it.
You can start a webserver on localhost with
'python -m SimpleHTTPServer 8000 > /tmp/simple-web-server.log 2>&1 &'