cfag
cfag

Reputation: 19

How to load a font in pdflib?

I'm trying to load an .otf font in Php 7.4.7 like this:

  1. Add the resources path which according to the logs looks like it worked:
$pdflib = new pdflib();
$pdflib->set_option('textformat=utf8');
$pdflib->set_option('SearchPath={{fullpath/to/my/fonts}}');

the log show up to this point no errors:

[New category:resource "SearchPath:fullpath/to/my/fonts"]
  1. But when loading the font like this:
$font = $pdflib->load_font("My-Font-Regular", "unicode", "embedding");

I get this error:

[Last exception 2516 in load_font]["Font 'My-Font-Regular' with encoding 'unicode': Font file (AFM, PFM, TTF, OTF etc.) or host font not found"]

I have tried utf-8 as encoding, giving full path when adding the search path and when loading the font, single and double curly braces when setting the search path but I could make more progress.

Also tried with no success:

$pdflib->set_option("stringformat=utf8");

I couldn't find any documentation for accepted encodings and the function it's not even described in the pdflib provided docs.

Any help would be greatly appreciated.

Upvotes: 0

Views: 1794

Answers (1)

Rainer
Rainer

Reputation: 2185

in general this looks fine, but there are a few potential pitfalls when using the extension based search:

  • the font file do not have one of the supported file extensions (like .ttf, .otf etc.)
  • the font name you use is different to font file base name. In your case, My-Font-Regular. Do your font file have this name with the extension .otf => My-Font-Regular.otf
  • the path fullpath/to/my/fonts (or a sub directory) has wrong read permissions for your PHP process.
  • when working on Windows, please take care, that you apply a complete absolute path. (see PDFlib 9 Tutorial, chapter 2.8 PHP Binding section File name handling in PHP for details.)

Please see PDFlib 9 Tutorial, chapter 6.4.4 Searching for Fonts section Extension-based search for font files for a detailed explanation.

As you have already enabled logging, you can enable more details by adding classes {filesearch=3}. Please see PDFlib 9 API Reference, chapter 1.3 Logging for more details. This might give you more details. And I'm sure, opening a Support case at PDFlib with sharing more details might also be an option.

Upvotes: 1

Related Questions