dompdf php,php – 如何在Dompdf中添加页眉和页脚?

dompdf FAQ起

Q: How can I add an image to a header or footer on every page?

A: You

can add images and shapes (line, rectangles, etc.) to every page using

PDF ‘objects’. A PDF object captures all rendering commands as a sort

of template that can then be added to multiple pages:

if ( isset($pdf) ) {

// Open the object: all drawing commands will

// go to the object instead of the current page

$footer = $pdf->open_object();

$w = $pdf->get_width();

$h = $pdf->get_height();

// Draw a line along the bottom

$y = $h - 2 * $text_height - 24;

$pdf->line(16, $y, $w - 16, $y, $color, 1);

// Add an initals box

$font = Font_Metrics::get_font("helvetica", "bold");

$text = "Initials:";

$width = Font_Metrics::get_text_width($text, $font, $size);

$pdf->text($w - 16 - $width - 38, $y, $text, $font, $size, $color);

$pdf->rectangle($w - 16 - 36, $y - 2, 36, $text_height + 4, array(0.5,0.5,0.5), 0.5);

// Add a logo

$img_w = 2 * 72; // 2 inches, in points

$img_h = 1 * 72; // 1 inch, in points -- change these as required

$pdf->image("print_logo.png", "png", ($w - $img_w) / 2.0, $y - $img_h, $img_w, $img_h);

// Close the object (stop capture)

$pdf->close_object();

// Add the object to every page. You can

// also specify "odd" or "even"

$pdf->add_object($footer, "all");

}

编辑:

这是一步一步的说明:

在你的html文件的某个地方,靠近顶部,打开一个带有“text / php”类型的脚本标记:

检查是否设置了$pdf变量.在评估嵌入式PHP时,dompdf设置此变量.

if ( isset($pdf) ) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值