I am using Express JS and Knexjs to read data from MySQL database, I can load the data from MySQL but I cannot see the result, it gives an error:
Error: Failed to load PDF document
my code as follow:
const express = require("express");
const router = express.Router();
const Lodash = require("lodash");
const jasper = require("node-jasper")({
path: "../lib/jasperreports-5.6.0",
reports: {
hw: {
jasper: "../reports/Customer_report.jasper",
jrxml: "../reports/Customer_report.jrxml",
conn: "in_memory_json",
},
},
});
const model = require("../model/customersModel");
router.get("/", async (req, res, next) => {
try {
model.getAll().then((customers) => {
// CustomerName, Address, CustomerContactName, Email, Telephone
let myDataSet = [];
Lodash.forEach(customers, (customers) => {
myDataSet.push({
CustomerName: customers.CustomerName,
Address: customers.Address,
CustomerContactName: customers.CustomerContactName,
Email: customers.Email,
Telephone: customers.Telephone,
});
});
var report = {
reports: "hw",
dataset: myDataSet,
};
console.log(report); // here I can see the data
var pdf = jasper.pdf(report);
res.set({
"Content-type": "application/pdf",
"Content-Length": pdf.length,
});
res.send(pdf);
});
} catch (error) {
next(error);
}
});
module.exports = router;
I can console.log the dataset but on the browser it gives me an error.
Error: Failed to load PDF document
question from:
https://stackoverflow.com/questions/65650349/how-to-integrate-node-jasper-with-expressjs-knexjs-and-mysql 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…