我正在尝试使用highcharts-export-server:3.0.0-beta.1,以避免重复。我用的是快速节点服务器。
这是我的package.json:
{
"name": "expresspdftest",
"version": "0.1.0",
"private": true,
"scripts": {
"preinstall": "export <setting>=<value>",
"start": "node ./bin/www"
},
"dependencies": {
"base64-img": "^1.0.4",
"body-parser": "^1.20.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "^4.18.2",
"fs": "0.0.1-security",
"highcharts": "^7.1.1",
"highcharts-export-server": "^3.0.0-beta.1",
"http": "0.0.0",
"http-errors": "~1.6.2",
"jade": "~1.11.0",
"morgan": "~1.9.0",
"node-fetch": "^2.6.1",
"path": "^0.12.7",
"pdfmake": "^0.1.54",
"request": "^2.88.0",
"typescript": "^3.4.5",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^3.9.0"
}
}
这是我调用highcharts导出服务器的地方:
var express = require('express');
var router = express.Router();
var path = require("path");
var request = require("request");
const exporter = import('highcharts-export-server');
//DON'T WORRY, OTHER IMPORTS ARE CORRECTLY DONE
var fineco,graphic,rating,graphicB64,dd,riskComponent,today,negComponent,graphicComponent,errorMessage,graphicTitle;
logs.info('Logging Started..');
function createPdfBinary(pdfDoc, callback)
{
var fonts =
{
Roboto:
{
normal: path.join(__dirname,'..','public','fonts','Roboto-Regular.ttf'),
bold: path.join(__dirname,'..','public','fonts','Roboto-Medium.ttf'),
italics: path.join(__dirname,'..','public','fonts','Roboto-Italic.ttf'),
bolditalics: path.join(__dirname,'..','public','fonts','Roboto-MediumItalic.ttf')
}
};
var printer = new pdfMakePrinter(fonts);
var doc = printer.createPdfKitDocument(pdfDoc);
var chunks = [];
var result;
doc.on('data', function (chunk)
{
chunks.push(chunk);
});
doc.on('end', function ()
{
result = Buffer.concat(chunks);
callback(result);
});
doc.end();
}
/* GET pdf. */
router.get('/', function(req, res, next)
{
var Code = req.query.id;
var URL = appConfig.fidaxServiceUrl;
request(URL+Code,function(error,response,body)
{
if(!error && response.statusCode == 200)
{
var inputData = JSON.parse(body);
if (inputData != null || inputData != undefined)
{
var checkedData = modelValidator.validator(inputData);
var counterSott = 0, counterComment = 0;
fineco = logoEncoder.base64Sync(path.join(__dirname,"..","public","images","logo_Fineco.png"));
if(checkedData.Underlying != null || checkedData.Underlying != undefined ) counterSott = checkedData.Underlying.length;
if(inputData.AnnualCouponRates != null && inputData.AnnualCouponRates !=undefined && inputData.AnnualCouponRates != NaN && inputData.AnnualCouponRates != "NaN") counterComment = checkedData.AnnualCouponRates.length;
graphic = graphicConstructor.createChart(checkedData.HistoricalData);
today= dataMaker.getToday();
Highcharts(graphic);
}
else
{
logs.info("Dati in ingresso non validi "+" | Fida Code : "+Code);
res.send(response);
}
}else if (error)
{
logs.info(error.code+" | Fida Code : "+Code);
res.send(error.code);
}
else
{
errorMessage = "FIDA Code non valido.";
try
{
var errRes = JSON.parse(body);
errorMessage = errRes.Message;
} catch(e){}
logs.info(errorMessage+" | Fida Code : "+Code);
res.send(errorMessage);
}
});
});
async function Highcharts()
{
console.log(exporter);
console.log(typeof exporter);
await exporter.initPool();
exporter.startExport(graphic, function(err,exp)
{
if(err == false)
{
graphicB64 = exp.data;
graphicB64 = "data:image/png;base64,"+graphicB64;
switch(checkedData.Type)
{
case "OBB": rating = getRating.getRatingCell(checkedData.RatingSandP);
ratingData = getRating.getRatingData(checkedData.DataRatingSandP);
graphicComponent = getGraphicObb.getGraphicTable(graphicB64,counterComment);
graphicTitle = getGraphicTitle.getTitle(counterComment);
dd = obbPDF.Obbligazione(fineco,ratingData,rating,graphicComponent,checkedData,today,graphicTitle,Code);
break;
case "CER": riskComponent = getRisk.riskTable(checkedData.RiskGrade);
underlyingComponent = getUnderlying.underlyingTable(checkedData.Underlying);
informationTitle = getInfo.getInfoNeg(counterSott);
negComponent = getInfo.getInfoTable(counterSott,checkedData);
graphicComponent = getGraphicCert.getGraphicTable(graphicB64,counterSott);
dd = certPDF.Certificato(fineco,riskComponent,graphicComponent,underlyingComponent,informationTitle,negComponent,checkedData,today);
break;
}
exporter.killPool();
createPdfBinary(dd, function(binary)
{
logs.info("PDF Creato - Fida Code :"+Code);
res.contentType('application/pdf');
res.send(binary);
});
}
else
{
exporter.killPool();
logs.info(err+" | Fida Code : "+Code);
res.send(err);
}
});
}
module.exports = router;
当我运行我的服务器时,我得到这个错误:TypeError:exporter.startExport不是函数
你能帮帮我吗?
我希望它能像旧版本一样工作(不能使用旧版本,因为不再维护旧版本)
1条答案
按热度按时间djmepvbi1#
其原因可能如下:
enhancement/puppeteer
分支上的当前文档反映了最新beta版本(3.0.0-beta.2)中的工作原理我相信更新到
3.0.0-beta.2
应该可以解决这个问题。如果没有,请让我知道或创建一个新的问题GitHub,它将被调查。PS.还值得记住的是,
error
现在是传递给startExport
回调函数的第二个参数,而response
是第一个参数(与附加代码中的顺序不同)。