【问题标题】:Labels created with PHP FPDF Library slide down page使用 PHP FPDF 库创建的标签向下滑动页面
【发布时间】: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 是的,没错 :)

标签: php fpdf


【解决方案1】:

我认为问题源于x 的处理方式。它应该不同于y。为什么?因为x 需要在每打印第三个标签后重置。由于它只在打印 9 行后才进行测试和递增,因此肯定会造成 sluing。 (也许这是一个古老的表达式,用于指示程序导致一个新行,因为它已经超过了您要打印的列)。建议您在每次打印标签后都需要测试x,这样当它到达total_x_per_page(我认为真正的意思是total_x_per_row)时可以将其重置为0。 x 测试需要独立于y 测试;它需要在 y 测试之前,因为您的列将在行之前完成。

在伪代码中:

  • 打印标签
  • 如果行完成重置x,否则增加x
  • 如果页面完整,重置 y 和 x。

我对 Fpdf 的体验为零。我与(战斗)标签的经验可以追溯到几十年前 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 2012-12-19
    相关资源
    最近更新 更多