【问题标题】:Empty variable in header fpdf标头 fpdf 中的空变量
【发布时间】:2018-02-25 07:34:19
【问题描述】:

我尝试在标题中显示一个变量,如 Invoice 但不起作用,我使用 FPDF 但字段 $ordenTrabajo 为空,我尝试了这个:

<?php


    $ordenTrabajo=$_POST['oT_Escondido'];

    ob_end_clean(); //    the buffer and never prints or returns anything.
    ob_start(); // it starts buffering
    class PDF extends FPDF
    {
    // Cabecera de página



    function Header()
    {
        // Logo
        //$this->Image('../dist/img/logo.jpg',10,8,33);
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Movernos a la derecha
        $this->Cell(80);
        // Título
        $this->Cell(120,10,'Control de Empaques IKOR PUNTARENAS SA',0,1,'C');

        $this->SetFont('Arial','B',12);
        // Salto de línea
        $this->Ln(10);
        $this->Cell(40,10,'Orden de Trabajo: ',0,0);
        $this->Cell(40, 10, "GORE-5265", 0, 0);
        $this->Cell(13,10,'OC#: ',0,0);
        $this->Cell(40, 10, "OC-123456789", 0, 0);
        $this->Cell(30,10,'Peso: ',0,0);
        $this->Cell(40, 10, "19,45 KG", 0,0 );
        $this->Cell(50,10,'Cantidad de Cajas: ',0,0);
        $this->Cell(30, 10, "1000", 0, 1);

        $this->Cell(20,10,'Lote: ',0,0);
        $this->Cell(40, 10,'123456789', 0, 0);
        $this->Cell(50,10,'Numero de Parte: ',0,0);
        $this->Cell(40, 10, "PARTE-999999", 0, 0);
        $this->Cell(40,10,'Filtros por caja: ',0,0);
        $this->Cell(20, 10, "11", 0,0 );
        $this->Cell(50,10,'Cantidad de Filtros: ',0,0);
        $this->Cell(30, 10, "9999", 0, 1);
        $this->Ln(15);
        $this->Line(80, 45, 100, 45); // 20mm from each edge
        $this->Line(50, 45, 210-50, 45); // 50mm from each edge

    }

    public function setLote($name){
        $this->name = $name;
    }

    // Pie de página
    function Footer()
    {
        // Posición: a 1,5 cm del final
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Número de página
        //$this->Cell(300,10,'7FMIKO-022 REV.02',0,0,'C');
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
        $this->Cell(-15,10,'7FMIKO-022 REV.02',0,0,'C');
    }
    }

    // Creación del objeto de la clase heredada
    $pdf = new PDF('L');
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Times','',12);
    $pdf->Cell(30,10,$ordenTrabajo,0,1);
    $pdf->Output();
    ob_end_flush(); // It's printed here, because ob_end_flush "prints" what's in
                  // the buffer, rather than returning it
                  //     (unlike the ob_get_* functions)
    ?>

我该如何解决?谢谢

编辑

即使使用全局变量,我也无法在标题中显示值

$ordenTrabajo=$_POST['oT_Escondido'];

ob_end_clean(); //    the buffer and never prints or returns anything.
ob_start(); // it starts buffering
class PDF extends FPDF
{
// Cabecera de página



function Header()
{
    global $ordenTrabajo;
    // Logo
    //$this->Image('../dist/img/logo.jpg',10,8,33);
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Movernos a la derecha
    $this->Cell(80);
    // Título
    $this->Cell(120,10,'Control de Empaques IKOR PUNTARENAS SA',0,1,'C');

    $this->SetFont('Arial','B',12);
    // Salto de línea
    $this->Ln(10);
    $this->Cell(40,10,'Orden de Trabajo: ',0,0);
    $this->Cell(40, 10, "GORE-5265", 0, 0);
    $this->Cell(13,10,'OC#: ',0,0);
    $this->Cell(40, 10, "OC-123456789", 0, 0);
    $this->Cell(30,10,'Peso: ',0,0);
    $this->Cell(40, 10, "19,45 KG", 0,0 );
    $this->Cell(50,10,'Cantidad de Cajas: ',0,0);
    $this->Cell(30, 10, "1000", 0, 1);

    $this->Cell(20,10,'Lote: ',0,0);
    $this->Cell(40, 10,$ordenTrabajo, 0, 0);
    $this->Cell(50,10,'Numero de Parte: ',0,0);
    $this->Cell(40, 10, "PARTE-999999", 0, 0);
    $this->Cell(40,10,'Filtros por caja: ',0,0);
    $this->Cell(20, 10, "11", 0,0 );
    $this->Cell(50,10,'Cantidad de Filtros: ',0,0);
    $this->Cell(30, 10, "9999", 0, 1);

}

【问题讨论】:

    标签: php html pdf


    【解决方案1】:

    该方法用于渲染页眉。它由 AddPage() 自动调用,不应由应用程序直接调用。FPDF 中的实现是空的,因此如果需要特定处理,则必须对其进行子类化并覆盖该方法。

    来源:http://www.fpdf.org/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-13
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 2011-08-12
      • 2012-03-11
      • 2021-11-03
      相关资源
      最近更新 更多