gpt4 book ai didi

php - 如何使用 dompdf 生成目录?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:43:11 25 4
gpt4 key购买 nike

我正在使用 php 的 dompdf 库从 HTML 模板生成 PDF 报告。在该 html 模板中有一个目录部分。生成 PDF 时,我需要更新目录的页码。有谁知道我如何在 php 的 dompdf 库中实现这一点?

提前致谢。

最佳答案

我已经在 Drupal 中实现了这一点,我猜它也适用于其他 php 开源和框架。我将这段代码保存在脚本标签中

$GLOBALS['entity_page'][] =  $pdf->get_page_number();        

在存储页码的模板中。 模板的扩展名为 tpl.php现在在模块中在我添加了其他导出代码之后……

$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "normal");
$canvas->page_text(520, 805, "Page {PAGE_NUM}", $font, 9, array(0.4, 0.4, 0.4));

foreach ($GLOBALS['entity_page'] as $key => $val) {
$GLOBALS["entity_val"] = 0;
$GLOBALS["entity_y"] = 110;
$canvas->page_script('if($PAGE_NUM == 3 && $PAGE_NUM < 4){
$font = Font_Metrics::get_font("helvetica", "normal");
$x = 380;
$y = $GLOBALS["entity_y"];

$pdf->text($x, $y, "-------------------------".$GLOBALS["entity_page"][$GLOBALS["entity_val"]]."", $font, 12, array(0, 0, 0, 0.8));
$GLOBALS["entity_y"] = $GLOBALS["entity_y"] + 33;
$GLOBALS["entity_val"] = $GLOBALS["entity_val"] + 1;

}');
}

$pdf->text 这部分添加页码,在 y 轴位置上以恒定增量增加。其他全局变量 entity_y 和 entity_val 用于存储值。

关于php - 如何使用 dompdf 生成目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/692060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com