Initial commit
This commit is contained in:
27
index.js
Normal file
27
index.js
Normal file
@ -0,0 +1,27 @@
|
||||
const carbone = require('carbone');
|
||||
const express = require('express')
|
||||
|
||||
const PORT = 8000;
|
||||
const OPTIONS = { convertTo: 'pdf', lang: 'en-us', currencyTarget: 'USD' };
|
||||
|
||||
const app = express();
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({extended: true}))
|
||||
|
||||
app.post('/api/convert', (req, res) => {
|
||||
|
||||
// Generate a report using the sample template provided by carbone module
|
||||
// This LibreOffice template contains "Hello {d.firstname} {d.lastname} !"
|
||||
carbone.render('./node_modules/carbone/examples/simple.odt', req.body, OPTIONS, function(err, result){
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
res.set('Content-Type', 'application/pdf');
|
||||
res.end(result);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`PDF Converter listening on ${PORT}`);
|
||||
});
|
Reference in New Issue
Block a user