TCPDF pdf 中的特定字体
有人可以告诉我我做错了什么吗?我需要在 TCPDF 生成的 pdf 中使用 Arial 字体。 首先我尝试使用它: 1)我从Windows字体目录中获取Arial并将其放入TCPDF目录中。 2)接下来我在脚本中写道:
$fontname = $pdf->addTTFfont('../lib/tcpdf/arial.ttf', '', '', 32);
之后在 tcpdf/fonts 中出现 3 个文件(arial.ctg.z、arial.php 和 arial.z)。我认为一切都很好,但如果在 TCPDF 中我使用此字体:
$pdf->SetFont('arial', '', 16);
文档中的字体确实是 arial 但没有波兰语特定的歌曲(ąęłżńź)
我也尝试过自己准备字体: 我下载了 ttf2afm 和 makefontuni.php 脚本,然后在命令行中我写道:
ttf2ufm -a arial.ttf
php -q makefontuni.php arial.ttf arial.ufm
该命令还给了我 3 个文件(arial.ctg.z、arial.php 和 arial.z),但最终情况与之前相同。
我承认写入 pdf 的所有数据都是 UTF-8 格式,并且 TCPDF 构造如下:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'utf-8', false);
我不知道我做错了什么。 :(
Can somebody tell me what i am doing wrong? I need Arial font in my pdf generated by TCPDF.
First I've tried to use that :
1) I got Arial from windows fonts caltalog and put it in TCPDF directory.
2) Next I wrote in script :
$fontname = $pdf->addTTFfont('../lib/tcpdf/arial.ttf', '', '', 32);
After that in tcpdf/fonts appears 3 files (arial.ctg.z , arial.php and arial.z). I thought that everything was ok but if in TCPDF i use this font by:
$pdf->SetFont('arial', '', 16);
Font in document is indeed arial but without polish specific sings (ąęłżńź)
I've tried also prepare font by yourself :
I downloaded ttf2afm and makefontuni.php script then in command line I wrote this:
ttf2ufm -a arial.ttf
php -q makefontuni.php arial.ttf arial.ufm
that command gave me also 3 files (arial.ctg.z , arial.php and arial.z) but final situation is the same like before.
I've admit that all data writing to pdf is in UTF-8 and TCPDF construct is like this :
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'utf-8', false);
I don't know what am i doing wrong. :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您想使用自定义字体,请使用此工具
https://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
当您获取生成的文件时,只需将它们移动到/fonts 目录并使用相同的名称,设置 font-name 属性。
If you want to use a custom font use this tool
https://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
when you get the generated files just move them to the /fonts directory and with the same name they have, set the font-name attribute.
无需添加任何字体,使用 Dejavu Sans 字体,它内置了所有 UTF-8 字符,并且 TCPDF 已包含该字体。
http://www.tcpdf.org/examples/example_001.phps
No need to add any font, use the Dejavu Sans Font which has all the UTF-8 characters built-in and the TCPDF has it already..
http://www.tcpdf.org/examples/example_001.phps
这就是我用来将自定义字体包含到 TCPDF 中的方法。您只需要字体的 .ttf 文件。将其添加到服务器上您选择的文件夹中并运行此代码一次。 (我在导出时第一次运行它)然后你可以评论这一行,字体就会在那里。
为了将其添加到导出器,您应该将其添加为字体:
如果您希望将其设为默认值:
如果您不知道在 PDF 中使用的字体的实际名称是什么:
这将为您提供具体的信息导出文件中使用的字体名称。
运行该命令后,TCPDF 在其字体文件夹中创建了所需的所有文件,并且从现在开始就可以使用了。
如果您想重新添加相同的字体(修改后),您需要删除 tcpdf/fonts/your-font-name 中的字体文件。并再次运行此命令以重新添加它们。
This is what I use to include custom font to TCPDF. You need only .ttf file of the font. Add it in folder on your choice on the server and run this code once. ( I run it first time on export ) Then you can comment this row and the font would be there.
In order to add it to the exporter you should add it as font with:
And if you want it to be default:
If you don't know what is the actual name of the font to use in PDF:
This would give you the specific name of the font to use in the exported file.
After you run that command once the TCPDF creates all the file needed in its font folder and it is ready to use from now on.
If you want to re-add the same font (modified) you need to delete your font files in tcpdf/fonts/your-font-name. and run this command again to re-add them.
嗯,您确定您的 Arial 包含所有 UTF-8 字符吗?
我按照此处的说明 http://www.tcpdf.org/fonts.php
它起作用了。我遇到的问题是,我只能添加常规字体 - 一旦我添加粗体或斜体,然后相互更改,所有字符都会变成点。
所以目前我只使用常规字体,对于粗体我使用“dejavusans”(感谢 Miro)。
我的代码:
Hm, are you sure your Arial has all UTF-8 characters?
I followed instructions here http://www.tcpdf.org/fonts.php
and it worked. What I had problems was that I was only able to add Regular Font - as soon as I added Bold or Italic and then change from one another, all characters turned to dots.
So at the moment I'm only using my Regular font and for Bold I use 'dejavusans' (thanks to Miro).
My code:
我想这会帮助你解决性格问题。
上面的font-family支持UTF-8字符。
I think it will help you to fix the character issue.
Above font-family which supports the UTF-8 characters.
我遇到了同样的错误,我能够修复它,将下一个放在 de line 之后:
I had the same error i was able to fixed it putting the next, after de line:
如果将字体转换为 ctg.z/z/php 文件会更好。
您可以使用 http://fonts.palettize.me 转换 ttf 字体,然后将字体文件夹中的未压缩结果放入tcpdf 类。
然后您可以使用 $pdf->SetFont('jameelnoorinastaleeq', 'BI', 20); 添加它
Is better if you convert the font to ctg.z/z/php files.
You can convert ttf fonts with http://fonts.palettize.me and then put uncompressed result in fonts folder into tcpdf class.
Then you can add it with $pdf->SetFont('jameelnoorinastaleeq', 'BI', 20);