Skip to content
Permalink
802813970a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
48 lines (36 sloc) 1.28 KB
var http = require('http');
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var pdfmake = require('../js/index');
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ extended: false }));
function createPdfBinary(docDefinition) {
var fonts = {
Roboto: {
normal: path.join(__dirname, '..', 'examples', '/fonts/Roboto-Regular.ttf'),
bold: path.join(__dirname, '..', 'examples', '/fonts/Roboto-Medium.ttf'),
italics: path.join(__dirname, '..', 'examples', '/fonts/Roboto-Italic.ttf'),
bolditalics: path.join(__dirname, '..', 'examples', '/fonts/Roboto-MediumItalic.ttf')
}
};
pdfmake.setFonts(fonts);
var pdf = pdfmake.createPdf(docDefinition);
return pdf.getDataUrl();
}
app.post('/pdf', function (req, res) {
eval(req.body.content);
createPdfBinary(dd).then(function (binary) {
res.contentType('application/pdf');
res.send(binary);
}, function (error) {
res.send('ERROR:' + error);
});
});
var server = http.createServer(app);
var port = process.env.PORT || 1234;
server.listen(port);
console.log('http server listening on port %d', port);
console.log('dev-playground is available at http://localhost:%d', port);