To convert a document to PDF, we can use the command line utility Universal Office Converter (unoconv) .
It can be installed on your OS by any package manager, for example, to install it on Ubuntu using apt-get
sudo apt-get install unoconv
According to unoconv documentation
If you installed unoconv manually, make sure you have the necessary LibreOffice or OpenOffice packages installed
The following example shows how to call unoconv.
unoconv -f pdf sample_document.py
It generates a PDF document that contains the contents of the sample_document.py file
If you want to use the nodeJS program, you can invoke the command through a child process
Find the code below that demonstrates how to use the child process to use unoconv to create a PDF
const util = require('util'); const exec = util.promisify(require('child_process').exec); async function createPDFExample() { const { stdout, stderr } = await exec('unoconv -f pdf sample.js'); console.log('stdout:', stdout); console.log('stderr:', stderr); } createPDFExample();
source share