pl-lamballais - 2015-12-28

Here's the result, based on the last version of TCPDF available:
Take the tcpdf.php file
Line 12292 change the Bookmark call, adding two parameters: fontname and fontsize

          public function Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0), $x=-1, $link='',$fontname='',$fontsize='')

Line 12331, add the two new parameters in the outline array:

          $this->outlines[] = array('t' => $txt, 'l' => $level, 'x' => $x, 'y' => $y, 'p' => $page, 'f' => $fixed, 's' => strtoupper($style), 'c' => $color, 'u' => $link, 'n' => $fontname, 'z' => $fontsize);

Now, we'll change the addTOC function (which use outline array), located at line 21267. This function get the defaut font name and size at the beginning ($fontsize = $this->FontSizePt;$fontfamily = $this->FontFamily;). If our outline array don't have name or font size, we'll use these defaut values in order to maintain compatibiity.

So Line 21313, replace this bloc:

      if ($outline['l'] == 0)
        {
            $this->SetFont($fontfamily, $outline['s'], $fontsize);
        }
        else 
        {
            $this->SetFont($fontfamily, $outline['s'], $fontsize - $outline['l']);
        }

By this one:

       // If there is a fontname in the outline array, take it
        if ($outline['n'] != '')
        {
            $the_font_name = $outline['n'];
        }
        else
        {
            // Or take the basic fontname
            $the_font_name = $fontfamily;
        }

        // If there is a fontsize in the outline array, take it
        if ($outline['z'] != '')
        {
            $the_font_size = $outline['z'];
        }
        else
        {
            // Or take the basic fontsize
            $the_font_size = $fontsize;
        }

        $this->SetFont($the_font_name, $outline['s'], $the_font_size);

A few lines after, you will find the font setting for the number and also the style.

         // Old line
        //$this->SetFont($numbersfont, $fontstyle, $fontsize);
        // New line, using the font name, style and font size
        // from the book mark call
        $this->SetFont($the_font_name, $outline['s'], $the_font_size);

That's all. Now you can build your Bookmarks with the fontname and size you want, doing call as:

        $pdf->Bookmark($chaine_bookmark_chapitre, 0, 0, '', '', array(0,0,0),'','','times','10');

Would be nice if Nicola put this into next version. :)
Thanks a lot

 

Last edit: pl-lamballais 2015-12-28