php - FPDF - 内联粗体文本

标签 php html border fpdf

我正在尝试从 PHP 创建 PDF,出于法律原因,我们需要将免责声明的一部分加粗,并且需要概述免责声明。

我当前的代码使用:

if(isset($_POST['optout']) && $_POST['optout'] == "yes"){
    $pdf->Ln(5);
    $pdf->SetFont('Arial','I',12);
    $pdf->SetTextColor(128);
    $pdf->MultiCell(0,4,'This is my disclaimer. THESE WORDS NEED TO BE BOLD. These words do not need to be bold.',1,'C');
}

我目前正在为文档的其他部分使用 WriteHTML,我可以轻松地使用它来代替 MultiCell,但是我该如何创建边框?

所以我有两个选择..

原生 FPDF 函数

优点:给边框一个选项

缺点:没有简单的方法使内联文本加粗

WriteHTML 扩展类

优点:让我可以轻松地在行内添加粗体文本

缺点:不确定如何创建边框

建议?

最佳答案

您可以重写扩展的一部分,但使用扩展 writeHTML 可能更容易,然后在使用 writeHTML 创建的单元格上绘制一个带有边框的单元格(空文本)。通过适当调整您的单元格,它应该可以工作。

不要忘记使用 SetY 然后 SetX 来定位您的单元格。

例子:

if(isset($_POST['optout']) && $_POST['optout'] == "yes"){
   $pdf->Ln(5);
   $pdf->SetFont('Arial','I',12);
   $pdf->SetTextColor(128);

   //Your text cell
   $pdf->SetY($pos_Y);
   $pdf->SetX($pos_X);
   $pdf->writeHTML('This is my disclaimer. <b>THESE WORDS NEED TO BE BOLD.</b> These words do not need to be bold.');

   //Your bordered cell
   $pdf->SetY($pos_Y);
   $pdf->SetX($pos_X);
   $pdf->Cell($width, $height, '', 1, 0, 'C');
 } 

关于php - FPDF - 内联粗体文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22697527/

相关文章:

php/mysql 计算匹配条件的项目数

php - 如何使用 getAllChecked() 获取 dhtmlx 中检查的项目的文本

html - 打破单词,使其适合屏幕

javascript - 通过单击链接从数据库加载

php - 如何检索具有多个时区的记录

php - Youtube Data API v3 - Bad Request - 如何找出错误

iphone - 如何让 --webkit-tap-highlight-color 突出显示整个 DIV?

iphone - 是否可以向 UITableView 添加边框样式? (不是边框颜色/边框宽度)

c# - 在 silverlight xaml c# 中只有两个圆角的图像

html - CSS透明边框