Search code examples
phptcpdf

Is there an alternative to TCPDF::writeHTML to get inline bold text


I'm using TCPDF to generate a PDF with text only.

First I've used multiCell to add the text, now I wanted to have two words become bold (somewhere in the middle in my text). So I changed my code to use writeHTML and surrounded i with b-tags, and voila the words are now blod. But at the same time my document size went from 41kB to 205kB which seems a little extreme.

Is there anyway to use inline blod formatting in the text without increasing the PDF size by 300%?


Solution

  • As I said in comments, try with changing your font prior to using Cell() or Multicell() , example follows:

    $pdf=new PDF();
    ...
    $pdf->Cell(180,10,'bla bla',0,1,'C');
    $pdf->SetFont('Times','B',16);            //Change to bold
    $pdf->Cell(180,10,'bla bla bla',0,1,'C'); //this printed in bold
    $pdf->SetFont('Times','',12);             //Revert to plain font
    $pdf->Cell(180,10,'bla bla bla',0,1,'C');