php FPDF 添加新字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17480572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FPDF add new font
提问by Marco Muci?o
I'm using the FPDF library for PHP to generate reports, but now I need to use another font (Verdana) that isn't in the core fonts. I added the line:
我正在使用 PHP 的 FPDF 库来生成报告,但现在我需要使用不在核心字体中的另一种字体 (Verdana)。我添加了这一行:
$pdf->AddFont('Verdana','','verdana.php');
I copied the files verdana.php and verdana.z to the fonts directory. Every things works fine, if I use the next instructions:
我将文件 verdana.php 和 verdana.z 复制到字体目录。如果我使用以下说明,一切正常:
$pdf->SetFont('Verdana','',6);
But if I try to use the next instruction (to use the bold font):
但是,如果我尝试使用下一条指令(使用粗体):
$pdf->SetFont('Verdana','B',6);
I get the error:
我收到错误:
FPDF error: Undefined font: verdana B
I tried adding another font for the Verdana Bold:
我尝试为 Verdana Bold 添加另一种字体:
$pdf->AddFont('Verdana-Bold','B','verdanab.php');
Of course, I put the files verdanab.php and verdanab.z in the fonts directory. But I get the same error. What I'm missing or how to use both Verdana fonts (normal and bold)?
当然,我把文件verdanab.php和verdanab.z放在fonts目录下。但我得到了同样的错误。我缺少什么或如何使用 Verdana 字体(正常和粗体)?
Thanks in advance.
提前致谢。
回答by SeanWM
I read through an interesting article on this. It should help you with what you're looking for.
我阅读了一篇关于此的有趣文章。它应该可以帮助你找到你正在寻找的东西。
Adding TrueType Fonts to FPDF Documents
Maybe something like this:
也许是这样的:
$pdf->AddFont('Verdana','B','verdanab.php');
回答by silk_route11
make sure you have added the font directory at the top of the script before require('fpdf.php');
确保在 require('fpdf.php'); 之前在脚本顶部添加了字体目录;
define('FPDF_FONTPATH','./font/');
if you have already done that, then just remove 'B' from the setFont() method. Its a quick fix and not a good practice.
如果您已经这样做了,那么只需从 setFont() 方法中删除 'B'。它是一个快速修复,而不是一个好的做法。
$pdf->SetFont('Verdana','',6);
For more help you can go through this Adding new fonts and encoding support
如需更多帮助,您可以通过此 添加新字体和编码支持
回答by Ashutosh Srivastava
Use this syntax:
使用以下语法:
$pdf->AddFont('Verdana','','verdanab.php');
$pdf->AddFont('Verdana','','verdanab.php');
instead of using:
而不是使用:
$pdf->AddFont('Verdana','B','verdanab.php');
$pdf->AddFont('Verdana','B','verdanab.php');
回答by Stefan Vogt
I solved it by defining a font for each style:
我通过为每种样式定义字体来解决它:
$pdf->AddFont('Verdana','','verdana.php');
$pdf->AddFont('Verdanabold','','verdanabold.php');
Then use:
然后使用:
$pdf->SetFont('Verdana','',6); // Regular style
$pdf->SetFont('Verdanabold','',6); // Bold style
回答by user5510975
Standart Font Families:
标准字体系列:
Courier (fixed-width)
Helvetica or Arial (synonymous; sans serif)
Times (serif)
Symbol (symbolic)
ZapfDingbats (symbolic)
Here you can create your own .php file for Fpdf:
在这里您可以为 Fpdf 创建您自己的 .php 文件: