foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.94k stars 1.16k forks source link

Fallback font support #201

Open tambet opened 10 years ago

tambet commented 10 years ago

When a glyph does not exist in the primary font, it should look in a list of other candidate fonts to find it (like in prawn, see https://github.com/prawnpdf/prawn/issues/103)

shyamramesh commented 10 years ago

Need a provision in pdfkit to set a substitution font like (arial unicode) so that glyphs get substituted when it is not present in primary font .This is an important requirement to avoid text disappearing in final pdf for lack of glyph.

ramachandranmarimuthu commented 10 years ago

+1

devongovett commented 10 years ago

I'm working on it. The new font system that I'm developing will use my new font-manager module to get font fallback information from the OS automatically.

pluswave commented 10 years ago

how about fallback support in browser ? seems font-manager will just works on Node, am I right ?

devongovett commented 10 years ago

Yes, font-manager is for Node. For the browser, we'll have to include a set of fallback font data. The problem is that the data will make PDFKit HUGE. Not sure what the best thing to do is.

pluswave commented 10 years ago

Can we have a mechanism that, user can customize pdfkit to use fallback fonts (and user can select font files), but by default, don't use it ?

vsemozhetbyt commented 9 years ago

+1

Some notes.

  1. Sometimes characters not found in the default or embedded font make all the text scrambled, even simple ASCII chains.
  2. Someteimes if I embed big font (arialuni.ttf) I get completely blank document.
Blewin commented 7 years ago

Hey, is there any update on this feature? I need it.

gubikmic commented 5 years ago

Doesn't PDF allow to have text without any embedded fonts and then it's up to the rendering program or OS to select a default font?

It would be great if that was an option. Then instead of saying document.font('Helvetica') you could leave the default and for Chinese, Korean, Japanese, Greek, Russian, etc. you'd still get readable PDFs.

wentjun commented 4 years ago

Has anyone managed to figure out a good strategy to allow fallback fonts?

Been having some trouble rendering such sentences which consists of a combination of various languages (Vietnamese, and Chinese):

doc
  .fontSize(12)
  .font('Semibold')
  .text('Hanoi Hotel, Trần Huy Liệu, Giang Vo,巴亭郡河内越南', 166, 468, {
    width: 370,
  })

If not, how exactly can we make this work with the font-manager package?

wentjun commented 4 years ago

Ok, just an update, I decide to use [arial unicode] for the pdf generation instead of the project's main font (which uses PingFang SC). It wasn't ideal, but arial unicode was a good compromise as it supports a variety of languages which is perfect for internationalisation. (https://catalog.monotype.com/family/monotype/arial-unicode)

Fliens commented 2 years ago

I found a workaround!

Follow these instructions (You might have to use the 10 day trial | or use opensource FontForge but that did not work that good)

With these steps you can merge multiple fonts so there is no need for a fallback font. Works pretty good! :)

piersdeseilligny commented 1 year ago

This has been an issue for the past 9 years, and it makes developing language-inclusive software with PDFKit really difficult. For a lot of situations, the solutions and workarounds in this thread really don't help, they only help if you know exactly what fonts your users will need/want and what text they're going to be writing.

I'm going to be too busy over the next few months to look into it, but could someone more familiar with pdfkit suggest what a a correct way of doing this would be? Just so we have an idea of how complex it would be, and so that potential contributors know where to start looking.

A basic implementation could even ignore system font fallback, and only look for fallback glyphs amongst user-supplied and specified fonts.