无法使用 tcpdf 生成 pdf

发布于 2024-12-15 05:39:18 字数 1577 浏览 2 评论 0原文

在我的网站上,用户可以打印(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方觉久 2024-12-22 05:39:18

我认为问题在于,TCPDF 的目录 cachefonts (位于路径存储在常量 K_PATH_MAIN 中的文件夹中,通过默认这是 TCPDF 目录),您的网络服务器无法写入。不要将您自己的 fonts 目录与 TCPDF 内部使用的目录混淆。

fonts 目录必须是可写的,因为 addTTFfont 首先转换 TTF 文件并将转换的输出写入 fonts 目录。如果稍后将 SetFont 与“AveriaSans-light”一起使用,它会尝试包含这些文件,如果找不到这些文件,则会失败并显示“无法包含字体定义文件”。

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.

冰火雁神 2024-12-22 05:39:18

vstm 是正确的,但也可能是因为你有

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

大写 L 并且在你的代码中是 小写 l

vstm is right but also maybe because you have

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

with capital L and in your code is lowercase l

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文