每当保存数据时如何生成pdf?

时间:2018-08-05 13:13:00

标签: html node.js pdf

每当从html表单提交数据时,我都需要生成PDF。但是PDF不应是html页面的图像。我已经将node.js用于服务器实现。我从表单中的字段插入的所有数据都应包含在PDF中。另外,我已经使用mongodb作为数据库。

var express=require('express');
var app=express();
var mongoose=require('mongoose');
var bodyparser=require('body-parser');
var outline=require('./schemas/outline');
var outcomes=require('./schemas/outcomes');


//making db connection
mongoose.connect('mongodb://127.0.0.1:27017/modulelist');
//checking db connection
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
    console.log("connected to db");
});


//setting client location
app.use(express.static(__dirname+"/client"));
//setting body parser
app.use(bodyparser.json());


//Insert modulelist data to db
app.post('/SaveModuleList',function(req,res){
    var mod=new outline(req.body);
    mod.save(function(err,docs){
        if(!err){
            res.json(docs);
        }else{
            console.log(err);
        }
    })
});

app.post('/SaveOutcomesList',function(req,res){
    var out=new outcomes(req.body);
    out.save(function(err,docs){
        if(!err){
            res.json(docs);
        }else{
            console.log(err);
        }
    })
});


app.listen(3000,function(){
    console.log("server runing in port 3000");
});

0 个答案:

没有答案