Xin Qian Ch'ang Xin Qian Ch'ang - 1 year ago 76
PHP Question

cannot generate pdf with tcpdf

on my site a user can print (in pdf) the nda he accepted
for some reason i cannot display the pdf

here the logic

first rewrite the rule

RewriteRule ^nda/?$ ndapdf.php?useSessionUser=1 [L]

then the php


$html = file_get_contents("/lib/nda.txt");
$html = str_replace("##user##", $_SESSION["currentUser"]);
$html = str_replace("##date##", date("Y-m-d h:i:s"));

$pdf->SetSubject("Accepted NDA");

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, "", PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, "", PDF_FONT_SIZE_DATA));

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setLanguageArray(array("w_page" => ""));
$fontname = $p->addTTFfont("/fonts/AveriaSans-light.ttf", "TrueTypeUnicode", "", 32);
$pdf->SetFont("arial", "", 10);
$pdf->writeHTML($html, true, false, true, false, "");

$pdf->Output("/home/comp/pdf/nda/$currentUser.pdf", "F");
header("Content-Type: application/pdf\n");

i get:

"TCPDF ERROR: Could not include font definition file: AveriaSans-light"

the font is: ll /fonts/

-rw-r--r-- 1 root root 85084 2011-11-02 17:51 AveriaSans-Light.ttf


Answer Source

I think the problem is, that the directories cache and fonts of TCPDF (residing in the folder which path is stored in the constant K_PATH_MAIN, by default this is the TCPDF-directory) are not writeable by your webserver. Don't confuse your own fonts-directory with the one used by TCPDF internally.

The fonts directory has to be writeable because addTTFfont first converts the TTF-file and writes the output of the conversion in to the fonts directory. If later on SetFont is used with "AveriaSans-light" it tries to include those files and fails with "Could not include font definition file" if they are not found.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download