How to use TCPDF in conjunction with static attributes?

1

I'm having problems using static attributes to display the texts with TCPDF ... Trying to execute the codes below, I'm getting the following error:

TCPDF ERROR: Some data has already been output, can not send PDF file

I really need help !!

No printPdf.php

class printPdf extends conn {
    private $text1;
    private $text2;

    public function setText1() {...}
    public function setText2() {...}
    public function callMtds() {
        $this->setText1();
        $this->setText2();
    }

    public function getText1() {
        return $this->text1;
    }
    public function getText2() {
        return $this->text2;
    }

}
$Nt = new printPdf();
$Nt->callMtds();

No printPdfStatic.php

require_once 'printPdf.php';
cass printPdfStatic extends printPdf {
    public static $text1;
    public static $text2;

    public function setAttr() {
        self::$text1 = $this->getText1();
        self::$text2 = $this->getText2();
    }
}
$Nt = new setAttr();

No MYPDF.php

require_once('tcpdf.php');
class MYPDF extends TCPDF {
  //Page header
  public function Header() {
    // get the current page break margin
    $bMargin = $this->getBreakMargin();
    // get current auto-page-break mode
    $auto_page_break = $this->AutoPageBreak;
    // disable auto-page-break
    $this->SetAutoPageBreak(false, 0);
    // set background image
    $img_file = '../img/boleto_bancario.jpg';
    $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
    // restore auto-page-break status
    $this->SetAutoPageBreak($auto_page_break, $bMargin);
    // set the starting point for the page content
    $this->setPageMark();
  }
}

No printPdf_Control.php

require_once 'printPdfStatic.php';//O problema aparece já quando faço a requisição do arquivo onde estão os atributos estáticos...
require_once 'MYPDF.php';

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);



// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Victor Almeida');
$pdf->SetTitle('Teste PDF 01');
$pdf->SetSubject('Iniciando com o uso de PDFs');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);

// remove default footer
$pdf->setPrintFooter(false);

// set auto page breaks
//$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetAutoPageBreak(FALSE, 0);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/por.php')) {
    require_once(dirname(__FILE__).'/lang/por.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', 'b', 8);

// remove default header
$pdf->setPrintHeader(false);

// add a page
$pdf->AddPage();


// -- set new background ---

// get the current page break margin
$bMargin = $pdf->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $pdf->getAutoPageBreak();
// disable auto-page-break
$pdf->SetAutoPageBreak(false, 0);
// set bacground image
$img_file = '../img/boleto_bancario.jpg';
$pdf->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$pdf->setPageMark();


// Print a text

$pdf->Text(108.0, 96.6, printPdfStatic::$text1);

$pdf->Text(2.0, 103.0, printPdfStatic::$text2);



// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('Teste_PDF_01.pdf', 'I');
    
asked by anonymous 16.07.2015 / 19:30

1 answer

1

It was necessary to clear the buffer with ob_clean(); shortly after requesting require_once 'printPdfStatic.php'; in the printPdf_Control.php file. As suggested by the user @Daniel Waghorn here .

    
17.07.2015 / 18:24