I am currently working on a project where I need to embed fonts into an existing PDF file that has some fonts that are not embedded. My primary goal is to ensure that all fonts used in the PDF are embedded, even if I have to use substitute fonts. I initially attempted to achieve this using PDFlib in Node.js, but I encountered an issue where the embedded fonts had different names, such as "Arial-7572" instead of "Arial."
Here's the code snippet I used with PDFlib:
const firstPage = await pdfDoc.getPages()[0];
pdfDoc.registerFontkit(fontkit);
const Arial = await pdfDoc.embedFont(fs.readFileSync('Arial.ttf', null));
firstPage.setFont(Arial);
I'm open to solving this problem with PDFlib, I'm also interested in alternative approaches using other libraries or tools like Ghostscript. My main objective is to have all fonts in the PDF file embedded, even if I need to substitute fonts. For instance, instead of embedding "Arial," I might embed a similar font like "Arimo." However, when inspecting the PDF properties, all fonts should be listed as embedded.
Can anyone provide guidance or a solution to achieve this font embedding goal in Node.js or through other libraries/tools?
Please don't suggest any website that can solve this issue.