PDFlib 将 table 放在定义的限定框底部

PDFlib place table on bottom of defined fitbox

我在 PDFlib PHP 中创建了一个 table 并将限定框的坐标定义如下:

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

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

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

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, "");
}

我找到了答案。在 fit_table$optlist 中,您可以定义 table 的位置(如果您希望它位于限定框的底部)如下所示:

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