【发布时间】: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, "");
}
【问题讨论】: