-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Find a way to inject fonts that are loaded on websites
Line 163 in f7bd7b7
| // TODO: Find a way to inject fonts that are loaded on websites |
await Promise.all(canvasToImagePromises);
}
if (args.debug === 'url') {
process.stdout.write(url);
}
if (!args.debug) {
// @ts-ignore
const pdfContent = await report.pdfPage(page, pdfOptions);
await browser.close();
if (server) await server.close();
debug('Closed chrome instance and express server');
const finalPdf = await PDFDocument.create();
if (pathToStaticFiles) {
finalPdf.registerFontkit(fontkit);
const fontsToInclude = await glob(
path.join(pathToStaticFiles, '**', '*.ttf')
);
await Promise.all(
fontsToInclude.map(async (fontToInclude) => {
const fontBytes = await fs.promises.readFile(fontToInclude);
return finalPdf.embedFont(fontBytes);
})
);
} else {
// TODO: Find a way to inject fonts that are loaded on websites
}
const content = await PDFDocument.load(pdfContent);
const contentPages = await finalPdf.copyPages(
content,
content.getPageIndices()
);
for (const contentPage of contentPages) {
finalPdf.addPage(contentPage);
}
const pdfBytes = await finalPdf.save();
if (args.outputPath) {
const outputPath = path.isAbsolute(args.outputPath)
? args.outputPath
: path.join(process.cwd(), args.outputPath);
try {
await lstat(outputPath);
} catch (_) {
await mkdir(outputPath.substring(0, outputPath.lastIndexOf(path.sep)), {
recursive: true,
});
}
debug('Writing file at', args.outputPath);
await writeFileAsync(args.outputPath, pdfBytes);
debug('PDF generation has been successfully finished!');
return args.outputPath;
}
debug('Return pdf content to stdout');
return pdfBytes;
}
};
export default pdfGenerator;
eleted file mode 100644
ndex 4db3c18..0000000
++ /dev/null78f88a675283aab6c4f769fcb75606b090bff005