无法使用 tcpdf 生成 pdf
在我的网站上,用户可以打印(pdf 格式)他接受的保密协议 由于某种原因,我无法在此处显示 pdf,
逻辑
首先重写规则,
.htaccess
RewriteRule ^nda/?$ ndapdf.php?useSessionUser=1 [L]
然后是我得到的 php
<?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"));
require("/lib/web/tcpdf/config/lang/eng.php");
require("/lib/web/tcpdf/tcpdf.php");
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, "UTF-8", false);
$pdf->SetCreator("mysite");
$pdf->SetAuthor("author_name");
$pdf->SetTitle("NDA");
$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->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$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->AddPage();
$pdf->writeHTML($html, true, false, true, false, "");
$pdf->lastPage();
$pdf->Output("/home/comp/pdf/nda/$currentUser.pdf", "F");
header("Content-Type: application/pdf\n");
read("/home/comp/pdf/nda/$currentUser.pdf");
:
“TCPDF 错误:无法包含字体定义文件:AveriaSans-light”
字体为:ll /fonts /
-rw-r--r-- 1 root root 85084 2011-11-02 17:51 AveriaSans-Light.ttf
谢谢
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
.htaccess
RewriteRule ^nda/?$ ndapdf.php?useSessionUser=1 [L]
then the php
<?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"));
require("/lib/web/tcpdf/config/lang/eng.php");
require("/lib/web/tcpdf/tcpdf.php");
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, "UTF-8", false);
$pdf->SetCreator("mysite");
$pdf->SetAuthor("author_name");
$pdf->SetTitle("NDA");
$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->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$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->AddPage();
$pdf->writeHTML($html, true, false, true, false, "");
$pdf->lastPage();
$pdf->Output("/home/comp/pdf/nda/$currentUser.pdf", "F");
header("Content-Type: application/pdf\n");
read("/home/comp/pdf/nda/$currentUser.pdf");
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
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于,TCPDF 的目录
cache
和fonts
(位于路径存储在常量K_PATH_MAIN
中的文件夹中,通过默认这是 TCPDF 目录),您的网络服务器无法写入。不要将您自己的fonts
目录与 TCPDF 内部使用的目录混淆。fonts
目录必须是可写的,因为addTTFfont
首先转换 TTF 文件并将转换的输出写入fonts
目录。如果稍后将SetFont
与“AveriaSans-light”一起使用,它会尝试包含这些文件,如果找不到这些文件,则会失败并显示“无法包含字体定义文件”。I think the problem is, that the directories
cache
andfonts
of TCPDF (residing in the folder which path is stored in the constantK_PATH_MAIN
, by default this is the TCPDF-directory) are not writeable by your webserver. Don't confuse your ownfonts
-directory with the one used by TCPDF internally.The
fonts
directory has to be writeable becauseaddTTFfont
first converts the TTF-file and writes the output of the conversion in to thefonts
directory. If later onSetFont
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.vstm 是正确的,但也可能是因为你有
大写 L 并且在你的代码中是 小写 l
vstm is right but also maybe because you have
with capital L and in your code is lowercase l