我创建了一个FPDF文档,它将一个图像放在标签纸上,标签上有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;
}
?>发布于 2018-12-09 17:02:37
我认为问题源于如何处理x。它应该与y不同。为什么?因为x需要在打印第三个标签之后重新设置。由于它只在9行打印后进行测试和递增,因此肯定会导致泄气。(也许这是一个旧的表达式,用于指示程序导致新行,因为它已经超过了要打印的列)。建议您需要在每次打印标签之后测试x,所以当它到达total_x_per_page (我认为这实际上是指total_x_per_row)时,它可以被重置为0。x测试需要独立于y测试;它需要在y测试之前,因为列将在行之前完成。
在伪码中:
我对Fpdf的经验是零。我打(打)标签的经验可以追溯到几十年前:)
https://stackoverflow.com/questions/53692280
复制相似问题