I was trying to make some static attributes to appear as the text of the pdf as follows, but I'm getting this error message:
TCPDF ERROR: Some data has already been output, can't send PDF file
I really do appreciate some help !!
On 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();
On printPdfStatic.php
require_once 'printPdf.php';
class printPdfStatic extends printPdf {
public static $text1;
public static $text2;
public function setAttr() {
self::$text1 = $this->getText1();
self::$text2 = $this->getText2();
}
}
$Nt = new setAttr();
On 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();
}
}
On printPdf_Control.php
require_once 'printPdfStatic.php';
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');