ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 一、页边距 ``` $PDF_MARGIN_LEFT = 5; $PDF_MARGIN_TOP = 30;//留给页眉的空间 $PDF_MARGIN_RIGHT = 5; $pdf->SetMargins($PDF_MARGIN_LEFT, $PDF_MARGIN_TOP, $PDF_MARGIN_RIGHT); ``` # 二、页眉、页脚 和设置字体一样,页眉页脚设置后会对之后的所有页有效 ## 1、页眉 ``` //页眉logo $PDF_HEADER_LOGO = __DIR__."/image/logo.png"; //logo宽度 $PDF_HEADER_LOGO_WIDTH = 15; //设置页眉字体 $pdf->setHeaderFont(Array('stsongstdlight', '', '10')); $PDF_HEADER_TITLE = "土豆刚(Potatog)"; $PDF_HEADER_STRING = "PDF生成示例\n基础demo"; //顶部标题颜色 $headerColor = array(254,0,0); //页眉线条颜色 $headerLineColor = array(0,0,255); $pdf->SetHeaderData($PDF_HEADER_LOGO, $PDF_HEADER_LOGO_WIDTH, $PDF_HEADER_TITLE, $PDF_HEADER_STRING, $headerColor, $headerLineColor); ``` 如果也显示页眉 ``` $pdf->setPrintHeader(false); ``` ## 2、页脚 ``` //页脚字体颜色 页码 $footerColor = array(254,0,0); //页脚线条颜色 $footerLineColor = array(0,0,255); $pdf->setFooterData($footerColor, $footerLineColor ); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); ``` 效果图 ![](https://img.kancloud.cn/31/c3/31c36c3994916b210a33804a42e5b887_1018x287.png) 有时候为了方便,可以显示坐标,网格 ``` //坐标 $pdf->SetFont('stsongstdlight', '', 5, '', true); for ($x = 5;$x < 205; $x += 5) { $pdf->Text($x, 0,".".$x); } for ($y = 5;$y <= 270; $y += 5) { $pdf->Text(0, $y,$y."."); } //网格线 $pdf->SetFont('stsongstdlight', '', 5, '', true); for ($x = 5;$x < 205; $x += 5) { for ($y = 5;$y <= 270; $y += 5) { $pdf->Text($x, $y,"."); } } ``` ![](https://img.kancloud.cn/84/f1/84f1fca3123496dd68a57d1a791b4c6b_998x138.png)