【问题标题】:PDFLib tables PHPPDFLib 表 PHP
【发布时间】:2020-04-21 07:13:44
【问题描述】:

我是 PDFlib 的新手,需要同样的指导。我在 pdflib 中添加了一个表格,其中一行有一个文本。现在我只希望文本的金额和日期部分以粗体显示,不知道我该怎么做。 这就是我现在所拥有的;

$font = $p->load_font("Helvetica", "unicode", "");
$optlistFourthRowFirstColumnTbl3 = "colwidth=100 colspan=4 fittextline={position={left bottom} font=" . $font . " fontsize=7.5}";

$row4Text = "\n\nYour Total amount is ".$aData['price']['total price']." ".$aData['currency']." and should be paid by".$invoiceDateOfPayment->format( 'd.m.Y' )." at the latest.";
$tbl3 = $p->add_table_cell( $tbl3, 1, $row, $row4Text, $optlistFourthRowFirstColumnTbl3 );
$row++;

但这只是给了我正常的整个文本,而我想要的是这样的;

您的总金额为 45.00 $,最迟应在 21.05.2020 之前支付。

【问题讨论】:

    标签: php pdflib


    【解决方案1】:

    您需要为此类单元格使用粗体。您可以在 PDFlib 说明书的代码示例中看到这一点: table/starter_table 在标题描述中使用粗体文本单元格。

        /* ---------- row 1: table header (spans all columns) */
    $row = 1; $col = 1;
    $font = $p->load_font("NotoSerif-Bold", "unicode", "");
    if ($font == 0) {
        echo("Error: " . $p->get_errmsg());
        exit(1);
    }
    
    $optlist = "fittextline={position=center font=" . $font . " fontsize=14} " .
    "colspan=" . $colmax;
    
    $tbl = $p->add_table_cell($tbl, $col, $row, $headertext, $optlist);
    if ($tbl == 0) {
        echo("Error: " . $p->get_errmsg());
        exit(1);
    }
    

    table/mixed table contents

        /* Load the font */
    $boldfont = $p->load_font("Helvetica-Bold", "unicode", "");
    if ($boldfont == 0)
            throw new Exception("Error: " . $p->get_errmsg());
    ...
    /* ---------------------
     * Adding the first cell
     * ---------------------
     * 
     * The cell will be placed in the first column of the first row and will
     * span three columns. 
     * The first column has a width of 50 points.
     * The text line is centered vertically and horizontally, with a margin
     * of 4 points from all borders. 
     */
    $optlist = "fittextline={font=" . $boldfont . " fontsize=12" .
        " position=center} margin=4 colspan=3 colwidth=" . $c1;
    
    $tbl = $p->add_table_cell($tbl, 1, 1, "Our Paper Plane Models", $optlist);
    

    您可以在 fittextline={} 选项中应用字体句柄。当然你也可以通过使用fontnameencoding 选项来做一个隐式的load_font(),比如:

    $optlist = "fittextline={fontname=NotoSerif-Bold encoding=unicode fontsize=12" .
        " position=center} margin=4 colspan=3 colwidth=" . $c1;
    

    starter_table.php 示例也包含在 PDFlib 9 下载包中的 bind/php 目录(或任何其他支持的绑定)中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多