2

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.

1
  • From the docs it sounds like you use either set_options or load_font pdflib.com/pdflib-cookbook/fonts/font_configuration "If you know the font name and the font file name ... you can simply load the font", "Alternatively, you can supply an absolute path name such as p.set_option ..."
    – duncan
    Commented Jul 10 at 8:35

1 Answer 1

2

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.

1
  • Turns out I was missing braces after "FontOutline=". Once I added that it worked out perfectly. Thank you.
    – Ney LS
    Commented Jul 10 at 14:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.