Ney LS
Ney LS

Reputation: 27

PDFlib embed font

I am able to embed fonts before, using the code below.

pdf_set_parameter($pdf, "FontOutline", "Times=$fontdir/times.ttf");
$font = pdf_findfont($pdf, "Times", "winansi", 1);
pdf_setfont($pdf,$font,$font_size);
$p->setfont( $font,$fontsize);

But it seems this is now deprecated in new PDFLib version. I am now trying the code below as shown in the cookbook.

$p->set_option("FontOutline=Times=".$fontdir."/times.ttf");
$times_font = $p->load_font("Times", "unicode","");
$p->setfont( $times_font,$fontsize);

I am getting this error message: PDFlibException: Option 'FontOutline' has odd number of values...

Please help.

Upvotes: 2

Views: 122

Answers (1)

Rainer
Rainer

Reputation: 2185

I am getting this error message: PDFlibException: Option 'FontOutline' has odd number of values...

indeed, the option you apply is wrong.

You might find this well explained in the PDFlib 10.0.2 Tutorial, chapter 6.3.4: how to use FontOutline resource to find the font

For a detailed introduction into the powerful PDFlib option list, please check out PDFlib 10.0.2 API reference, 1.1 "Option Lists".

So I expect when you use

$p->set_option("FontOutline={Times=".$fontdir."/times.ttf"});
$times_font = $p->load_font("Times", "unicode","");
$p->setfont( $times_font,$fontsize);

Or you specify $fontdir as SearchPath and then simple use:

$p->set_option("SearchPath={{".$fontdir."} {/further/directory}");
$p->set_option("FontOutline={Times=times.ttf"});
$times_font = $p->load_font("Times", "unicode","");
$p->setfont( $times_font,$fontsize);

Please honor also, that you can specify the font (fontname or fonthandle and fontsize) also in the option list for fit_textline() of add/create_textflow().

This make it often much more easier, as always set the font with setfont()

About font embedding:

You can control the font embedding with the load_font() option embedding. Since PDFlib 10 this the default is true. When you use an outdated PDFlib version, you have to set embedding=true as well when loading the font.

Upvotes: 2

Related Questions