我正在尝试为fpdf中的特定“块”文本设置字母间距。我已经搜索了,并且只找到了一种方法来设置整个文档的字母间距,但即使这样也不起作用。文本被发布到php fpdf生成器。
$pdf->SetFont('Arial','b',85, LetterSpacing Here?);有什么帮助吗?
发布于 2016-09-01 22:36:25
根据其他提供的答案,我扩展了我们使用的FPDF类,以便下划线考虑用户定义的字母间距。
<?php
class Custom_FPDF extends FPDF
{
protected $FontSpacingPt; // current font spacing in points
protected $FontSpacing; // current font spacing in user units
function SetFontSpacing($size)
{
if($this->FontSpacingPt==$size)
return;
$this->FontSpacingPt = $size;
$this->FontSpacing = $size/$this->k;
if ($this->page>0)
$this->_out(sprintf('BT %.3f Tc ET', $size));
}
protected function _dounderline($x, $y, $txt)
{
// Underline text
$up = $this->CurrentFont['up'];
$ut = $this->CurrentFont['ut'];
$w = $this->GetStringWidth($txt)+$this->ws*substr_count($txt,' ')+(strlen($txt)-1)*$this->FontSpacing;
return sprintf('%.2F %.2F %.2F %.2F re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt);
}
}示例使用测试:
$pdf = new Custom_FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'BU', 11);
$pdf->SetFontSpacing(3);
$pdf->Cell(0, 10, 'Test of letter spacing with underline', 0, 1);
$pdf->SetFontSpacing(0);
$pdf->Cell(0, 10, 'Test of letter spacing with underline');
$pdf->Output();测试扩展FPDF版本1.81
发布于 2015-09-22 17:52:43
这将真正允许您进行字母间距:
// letter-spacing (0 for normal, 0.3 = 33%, 1 = 100%)
function SetCharSpacing($cs) {
$this->_out(sprintf('BT %.3F Tc ET',$cs*$this->k));
}致词:http://fpdf.de/forum/showthread.php?t=3241
发布于 2012-07-22 21:03:00
不幸的是,你不能只用函数直接做这个。这里你需要的是编写一个新的函数,用一些新的参数重新创建Cell() ...
等等..。已经有人这么做了!
在这里:FPDF Add-On by Patrick Benny
这是一份很棒的工作,你甚至不需要其他工作!:)
https://stackoverflow.com/questions/11126354
复制相似问题