【发布时间】:2018-12-09 12:26:17
【问题描述】:
我创建了一个 FPDF PDF 文档,该文档将图像放置在具有 9 行标签的标签纸上(下面的 PHP 代码)
每行标签之间没有空格/间隙,下一行标签紧随上一行开始。
### 问题:###
在打印标签时,每个标签上显示的图像从每个标签的顶部略微向下移动,导致标签的底行(第 9 行)与第 1 行明显不同。
我需要为每个标签添加额外的内容,如果此问题继续存在,部分内容将被截断。
我不明白为什么会这样,并且在代码中看不到任何明显的东西。这里有人能发现我做错了什么吗?
我的代码.....
use Fpdf\Fpdf as FPDF;
$current_x_position = 0;
$current_y_position = 0;
$total_y_per_page = 9;
$total_x_per_page = 3;
$pdf = new FPDF();
$pdf->SetMargins(0,0);
$pdf->SetAutoPageBreak(false);
$pdf->AddPage();
for($qty = 1; $qty <= 10; $qty++) {
label($current_x_position, $current_y_position, $pdf);
$current_y_position++;
if($current_y_position == $total_y_per_page) {
$current_x_position++;
$current_y_position = 0;
if($current_x_position == $total_x_per_page) {
$current_x_position = 0;
$current_y_position = 0;
$pdf->AddPage('P');
}
}
}
$pdf->Output();
function label($current_x_position, $current_y_position, $pdf) {
$left_margin = 7;
$top_margin = 15;
$label_width = 66;
$label_height = 30;
$current_x_position = $left_margin + ($label_width * $current_x_position);
$current_y_position = $top_margin + ($label_height * $current_y_position);
$pdf->Image('image.png', $current_x_position, $current_y_position+=1, $label_width, 10, 'png');
return;
}
?>
【问题讨论】:
-
跨标签是9行3列吗,即9行3列?
-
@DinoCoderSaurus 是的,没错 :)