Korzystam z TCPDF w celu wygenerowania pdf. W pdf ma być nagłówek w postaci tabelki, w którym część informacji jest wpisana ręcznie na sztywno, część informacji ma być pobierana z bazy danych oraz w nagłówku ma być zliczana ilość stron.
Póki co udało mi sie stworzyć tabelkę w nagłówku i przypisać dane na sztywno, problem pojawił się w sytuacji, kiedy chciałem by w tej tabeli zostały wstawione dane z bazy danych.
Zrobiłem zapytanie i...wyniki nie chcą sie wyświetlić w nagłówku tabeli, ale wyświetlają się w treści dokumentu $imie, $emission.
Jak zrobić by te zmienne wyświetlały się również w nagłówku?
<?php require_once('admin/strona_kod.php'); // Include the main TCPDF library (search for installation path). require_once('tcpdf/tcpdf.php'); //require_once('tcpdf/config/tcpdf_config.php'); require_once('tcpdf/config/lang/pol.php'); require_once('class/class.SQL.php'); $sql = new SQL; $sql->connection(); $imie=$set2['pole1']; $emission=$set2['emission']; class MYPDF extends TCPDF { //Page header $html1 = '<table cellspacing="0" cellpadding="1" border="1"> <tr> <td rowspan="2">1</td> <td rowspan="2">2</td> <td>'.$emission.'</td> </tr> <tr> <td>4</td> </tr> <tr><td>5</td><td rowspan="4">6</td><td>7</td></tr> <tr><td rowspan="3">8</td><td>9</td></tr> <tr><td>10</td></tr> <tr><td>11</td></tr> <tr> <td colspan="3">12</td> </tr> </table>'; $this->writeHTMLCell($w = 180, $h = 10, $x = '', $y = '', $html1, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = 'top', $autopadding = true); // Logo // $image_file = K_PATH_IMAGES.'logo_example.jpg'; // $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false); // Set font // $this->SetFont('helvetica', 'B', 20); // Title // $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M'); } // Page footer public function Footer() { // Position at 15 mm from bottom $this->SetY(-15); // Set font $this->SetFont('helvetica', 'I', 8); // Page number $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); } } // create new PDF document //$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); // create new PDF document $pdf = new MYPDF('P', 'mm', 'A4', true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 003'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data // set header and footer fonts // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) $pdf->setLanguageArray($l); } // --------------------------------------------------------- // set default font subsetting mode $pdf->setFontSubsetting(true); // Set font // dejavusans is a UTF-8 Unicode font, if you only need to // print standard ASCII chars, you can use core fonts like // helvetica or times to reduce file size. $pdf->SetFont('dejavusans', '', 14, '', true); // Add a page // This method has several options, check the source code documentation for more information. $pdf->AddPage(); // set text shadow effect $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal')); // Set some content to print $html = <<<EOD <h1>Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0000;color:black;"> <span style="color:black;">TC</span><span style="color:white;">PDF</span> </a>!</h1> <i>$emission is the first example of TCPDF $imie library.</i> <p>This text is printed using the <i>writeHTMLCell()</i> method but you can also use: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p> <p>PleLśśęąśćżźńłóŁÓĘŚŹŻĆŃ‚ae check the source code documentation and other examples for further information.</p> <p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a></p> EOD; // Print text using writeHTMLCell() $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); // --------------------------------------------------------- // Close and output PDF document // This method has several options, check the source code documentation for more information. $pdf->Output('pdf/001.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+
znalazłem tutaj taki wątek
Temat: PHPWciagniecie zmiennej do public function
i na podstawie tego dochodzę do wnioski, że jest jakiś problem chyba z pobieraniem wyników z zapytania
class MYPDF extends TCPDF { //Page header $nr='pati'; $czas=$z['osoba']; $html = <<<a <h2>Raport magazynowy</h2> <table border="1" cellpadding="4"> <tr><td>Typ dokumentu: 1</td><td>Nr:$nr</td><td>Data:$czas</td></tr> </table> a; // output the HTML content $this->writeHTML($html, true, false, true, false, '');
Wszystko sie wyświetla dobrze poza $czas. Co może być tego przyczyną?
ps. dodam, że pole osoba istnieje w tej tabeli, sprawdzałem też na innych polach

Ok, udało się znaleźć rozwiązanie

Pojawił się jeszcze jeden problem - polskie znaki w nagłówku.
Baza kodowana w utf-8, strona również.
W treści generowanego pdf-a są polskie znaki, brakuje ich niestety w nagłówku.
Może ktoś wie, jak to można zrobić?
Będę szukał rozwiązania w necie, ale jeśli ktoś wie, to proszę o pomoc.