【问题标题】:PDFlib place table on bottom of defined fitboxPDFlib 在定义的 fitbox 底部放置表格
【发布时间】:2021-08-30 15:01:14
【问题描述】:

我在 PDFlib PHP 中创建了一个表格,并将 fitbox 的坐标定义如下:

$llx = 350;
$lly = 500;
$urx = 600;
$ury = 800;

现在我希望表格从这些坐标的底部开始,如果我添加更多单元格,我希望表格增长到顶部。我怎样才能做到这一点?

到目前为止我写的函数(这里表格从顶部开始):

function createTable(pdflib $p, int $fontMedium, int $fontRegular, array $arrInput) {
    $tbl=0;
    $rowmax = 8;

    /* ---------- table header */
    $row = 1; $col = 1;

    $optlist = "margin=4 fittextline={position=center font=" . $fontMedium . " fontsize=10} " .
        "matchbox={fillcolor={#ffed00}} colspan=1 colwidth=200";

    $tbl = $p->add_table_cell($tbl, $col, $row, $arrInput['table']['tableHeading'], $optlist);
    if ($tbl == 0) {
        echo("Error: " . $p->get_errmsg());
        exit(1);
    }

    /* ---------- content rows */
    foreach($arrInput['table']['tableListings'] as $listings) {
        /* ----- Multi-line text with Textflow */
        // $row++;
        if ($row <= $rowmax) {
            $row++;
        } else {
            echo("Error: Too many Items for table");
            exit(1);
        }

        $font = $p->load_font("W-Regular", "unicode", "");
        if ($font == 0) {
            echo("Error: " . $p->get_errmsg());
            exit(1);
        }

        $optlist = "charref fontname=W-Regular encoding=unicode fontsize=10";

        $tf = $p->add_textflow(0, $listings, $optlist);
        if ($tf == 0) {
            echo("Error: " . $p->get_errmsg());
            exit(1);
        }

        $optlist = "margin=4 matchbox={fillcolor={rgb 0.9 0.5 0}} textflow=" . $tf;

        $tbl = $p->add_table_cell($tbl, $col, $row, "", $optlist);
        if ($tbl == 0) {
            echo("Error: " . $p->get_errmsg());
            exit(1);
        }
    }

    do {
        $optlist = "header=1 rowheightdefault=20 " .
        "stroke={{line=other}} ";

        $result = $p->fit_table($tbl, $llx, $lly, $urx, $ury, $optlist);
        if ($result ==  "_error") {
            echo("Couldn't place table: " . $p->get_errmsg());
            exit(1);
        }
    } while ($result == "_boxfull");

    $p->delete_table($tbl, "");
}

【问题讨论】:

    标签: php pdf pdflib


    【解决方案1】:

    我找到了答案。在 $optlistfit_table 中,您可以定义表格的位置(如果您希望它位于 fitbox 的底部),如下所示:

    $optlist = "header=1 rowheightdefault=20 "
            . "stroke={{line=horother linewidth=0.3}} "
            . "position={bottom} "; // statement to define position of the table in the fitbox
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 2021-11-30
      • 2017-01-31
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      相关资源
      最近更新 更多