I'm trying to generate a PDF file using Node js, Pdfkit and pdfkit-table using data stored in a Mysql database. I need to print records from a database to a table in a PDF document.
The following code generates an empty PDF file. Please help me solve the problem why it is not generating PDF file with data.
This is the index.js file.
var express = require('express'); var router = express.Router(); var PDFDocument = require('pdfkit'); var orm = require('orm'); var PDFDoc = require("pdfkit-table"); router.use(orm.express("mysql://root:@localhost:/kirula_fashion", { define: function (db, models, next) { models.news = db.define("ledger", { id : String, date : String, description : String, debit : String, credit : String, }); next(); } })); router.get('/', function(req, res, next) { var result = req.models.news.find({ }, function(error, news){ if(error) throw error; res.render('index', { news:news, title: '使用NodeJS生成PDF' }); }); }); router.get('/pdf', function(req, res, next) { var id = req.query.id; const doc = new PDFDocument(); const docTable = new PDFDoc(); var result = req.models.news.find({id: id}, function(error, newspost){ if(error) throw error; else{ if(newspost.length>0){ for(var i=0; i
I had the same problem with the data options, but for the row options, pdfkit-table worked just fine, maybe mapping [{..},{...}] to [[..],[ ...]] and then use line options