Open pofider opened 5 years ago
We've been encountering this problem while evaluating jsreports.
And its not just fonts which need to be merged but all identical objects (like logos). I did a simple proof of concept a few months ago which just merged all identical objects and that had alot of success in cutting down PDF size.
The chrome embeds fonts subset based on used characters. If we merge multiple pdfs together the font gets typically duplicated. The merge with "merge whole document" even duplicates font on every page. The size increase with "merge whole document" enabled is marginal so users with pdf size concern should always go with it.
The solution is to merge fonts during pdf merge. I share here some thoughts and we see if we get to it later.
The font in pdf consists of 3 parts.
I've tested that we can keep the cmap and font definition as it is. We just need to merge the font stream and produce one font which contains all characters. Unfortunately, the font created by chrome crashes in the opentype.js and some other font libs.
I found this code to work and it describes kind of the font structure. The missing thing is to take two fonts and put to the merge glyphs from both. http://stevehanov.ca/blog/?id=143
Here is some code for pdfjs which can be used to put the merge font to the pdf.