small pdf generator performance boosts

deepsource-autofix-76c6eb20
Dan Gowans 2022-10-11 15:42:56 -04:00
parent 476a044e63
commit 78a624f64d
1 changed files with 21 additions and 10 deletions

View File

@ -38,22 +38,33 @@ export const handler: RequestHandler = async (request, response, next) => {
response.send(pdf);
};
reportData.configFunctions = configFunctions;
reportData.dateTimeFunctions = dateTimeFunctions;
await ejs.renderFile(reportPath, reportData, {}, async (ejsError, ejsData) => {
const ejsCallbackFunction = async (ejsError: Error, ejsData: string) => {
if (ejsError) {
return next(ejsError);
}
await convertHTMLToPDF(ejsData, pdfCallbackFunction, {
await convertHTMLToPDF(
ejsData,
pdfCallbackFunction,
{
format: "letter",
printBackground: true,
preferCSSPageSize: true
});
},
undefined,
{
cacheBrowser: true,
remoteContent: false
}
);
return;
});
};
reportData.configFunctions = configFunctions;
reportData.dateTimeFunctions = dateTimeFunctions;
await ejs.renderFile(reportPath, reportData, {}, ejsCallbackFunction);
};
export default handler;