1

Hi folks,

I've been going over the examples and searched the form, but i can't figure out how to set a default font;

i have a variable $font which has the value freeserif
so now i want to set the default font with the following code:
$html2pdf->pdf->setDefaultFont($font);

this returns: Fatal error: Call to undefined method MyPDF::setDefaultFont() ....

also i have tried this: $html2pdf->pdf->setDefaultFont('freeserif');
which did return a pdf instead of an error, although the plain text that was parsed looked like arial, the html looked like this: 来汩敶攠瑥⁶敲浥汤敮 瀠畷⁣潲牥獰潮摥湴楥⁥
so, basicly... just to understand how to use a different font (present in the fonts folder that came with the zip), how do i set this? Am i missing something here?

Thanks!
Marco

2

With a font-family on a PAGE tag.

look at the examples (like utf8.php) in the ZIP file
Ancien pseudo : lolo

3

Thanks Spipu,

Still getting the same error... just hardcoded 'freeserif' for testing, though the variable $font exsists with value freeserif

i've set (for testing) the PAGE tag like:
<page backtop="<?php echo $bodyT.'mm'; ?>" backbottom="<?php echo $bodyB.'mm'; ?>" backleft="<?php echo $bodyL.'mm'; ?>" backright="<?php echo $bodyR.'mm'; ?>" backimg="<?php echo $imgURL; ?>" backimgx="<?php echo $imgXpos; ?>" backimgy="<?php echo $imgYpos; ?>" backimgw="<?php echo $imgW; ?>" style="font-size: <?php echo $fontsize."pt"; ?>; font-family: freeserif; " >

<?php // instead of the above font-family, use: if ($font) { echo "font-family: ".$font.";"; } ?>

if ($font) {
$html2pdf->pdf->setDefaultFont('freeserif');
// instead of the above function use: $html2pdf->pdf->setDefaultFont($font);
}

4

why do you call setDefaultFont on $html2pdf->pdf ? it is on $html2pdf...

and you don't need it. look at the utf8 example !


    $content = '<page style="font-family: freeserif">...</page>';

    $html2pdf = new HTML2PDF();
    $html2pdf->writeHTML($content);
    $html2pdf->Output('utf8.pdf');
Ancien pseudo : lolo

5

okay... i've mistaken the instructions on the use of the function then!

like your example... i have the font-family now (only) on the PAGE tag, for testing now hardcoded: font-family: times;
The error is gone, though the PDF result is actually still in ARIAL

Am i missing something else?

6

i think i have found the solution...

understanding the theory that you have to add a style to a tag, i found that i had my </PAGE> tag closed before writing the entire content so that was basicly it!

@spipu: thanks for your help... it sure is a great script!

7

marmachine (./6) :
i found that i had my tag closed before writing the entire content so that was basicly it!


bang

boing
Ancien pseudo : lolo

8

mur

9

Spipu (./4) :
why do you call setDefaultFont on $html2pdf->pdf ? it is on $html2pdf...

and you don't need it. look at the utf8 example !


    $content = '<page style="font-family: freeserif">...</page>';

    $html2pdf = new HTML2PDF();
    $html2pdf->writeHTML($content);
    $html2pdf->Output('utf8.pdf');



I used this it is working fine for first page.

$content = '<page style="font-family:futura; font-size:16px;">...</page><page style="font-family:futura; font-size:16px;">...</page>';


When I do this it will give me an error massage like this

TCPDF ERROR: Could not include font definition file: futura.

Note: there was not problem in font or path of font. I used every thing.

becase if I use
$content = '<page style="font-family:futura; font-size:16px;">...</page><page>...</page>';
than it is working fine but when use style in second page it gives above error.

Can any one please guide me about this matter?

Thanks