Method to generate PDF files: Use Node.js to connect to MySQL database
P粉154798196
P粉154798196 2023-08-25 14:23:44
0
1
528

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

P粉154798196
P粉154798196

reply all (1)
P粉924915787

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

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!