I'm trying to use highcharts-export-server: 3.0.0-beta.1 , to avoid PhantomJs. I'm using an express node server.
This is my 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"
}
}
This is where I call highcharts export server :
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;
I get this error when I run my server : TypeError: exporter.startExport is not a function
Can you help me, pls?
I expect it works like old version (can't use old version cause of PhantomJs is not maintained anymore)
The reason for this might be the following:
enhancement/puppeteer
branch reflects what works in the latest beta version (3.0.0-beta.2)I believe that updating to 3.0.0-beta.2
should solve it. If not, please let me know or create a new issue on GitHub and it will be investigated.
PS. It's also worth keeping in mind that error
is now the second argument passed to the startExport
callback whereas the response
is the first (different order than in your attached code).