I am not sure where I am writing to the output stream before calling $pdf->Output.
I did have a print statement for the HTML, but that was commented out.
I basically took the example and replaced the canned table with my own.
Here is the redone example:
<?php//============================================================+// File name : example_048.php// Begin : 2009-03-20// Last Update : 2013-05-14//// Description : Example 048 for TCPDF class// HTML tables and table headers//// Author: Nicola Asuni//// (c) Copyright:// Nicola Asuni// Tecnick.com LTD// www.tecnick.com// info@tecnick.com//============================================================+/** * Creates an example PDF TEST document using TCPDF * @package com.tecnick.tcpdf * @abstract TCPDF - Example: HTML tables and table headers * @author Nicola Asuni * @since 2009-03-20 */// Include the main TCPDF library (search for installation path).require_once('tcpdf_include.php');$field_lengths[]="50";$field_lengths[]="200";$field_lengths[]="40";$field_lengths[]="40";$field_lengths[]="40";$field_lengths[]="40";$field_lengths[]="40";$field_lengths[]="200";$field_names[]="Date";$field_names[]="Job Name";$field_names[]="Client Code";$field_names[]="Client PO Number";$field_names[]="Your PO Number";$field_names[]="Job Number";$field_names[]="Amount";$field_names[]="Remarks";$field_orientations[]="center";$field_orientations[]="left";$field_orientations[]="center";$field_orientations[]="center";$field_orientations[]="center";$field_orientations[]="center";$field_orientations[]="right";$field_orientations[]="left";functiongenerate_field($width,$align,$val){return'<td align="'.$align.'" width="'.$width.'">'.$val.'</td>';}functiongenerate_row($invals,$field_orientations,$field_lengths,$header=0,$style=''){if($style!='')$html='<tr style="'.$style.'">';else$html='<tr>';$field_orientation="center";$index=0;$vals=$invals;foreach($valsas$val){if(!$header)$field_orientation=$field_orientations[$index];$length=$field_lengths[$index];$html.=generate_field($length,$field_orientation,$val);$index++;}$html.='</tr>';return$html;}// create new PDF document$pdf=newTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false);// set document information$pdf->SetCreator(PDF_CREATOR);$pdf->SetAuthor('Nicola Asuni');$pdf->SetTitle('TCPDF Example 048');$pdf->SetSubject('TCPDF Tutorial');$pdf->SetKeywords('TCPDF, PDF, example, test, guide');// set default header data$pdf->SetHeaderData(PDF_HEADER_LOGO,PDF_HEADER_LOGO_WIDTH,PDF_HEADER_TITLE.' 048',PDF_HEADER_STRING);// set header and footer fonts$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN,'',PDF_FONT_SIZE_MAIN));$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA,'',PDF_FONT_SIZE_DATA));// 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)if(@file_exists(dirname(__FILE__).'/lang/eng.php')){require_once(dirname(__FILE__).'/lang/eng.php');$pdf->setLanguageArray($l);}// ---------------------------------------------------------// set font$pdf->SetFont('helvetica','B',20);// add a page$pdf->AddPage();$pdf->Write(0,'Invoice for Joe Blow of Insane Clown Posse','',0,'L',true,0,false,false,0);$pdf->SetFont('helvetica','',8);// -----------------------------------------------------------------------------// Table with rowspans and THEAD$tbl='<table border="1" cellpadding="2" cellspacing="2">';$tbl.='<thead>';$tbl.=generate_row($field_names,"",$field_lengths,1,"background-color:#FFFF00;color:#0000FF;");$tbl.='</tr></thead>';$tbl.=generate_row(explode("~","Mar 1, 2013~My Terrific Job~K47~4405~20131~1105~12.34~request 104294501, minimum charge per job of $23.00"),$field_orientations,$field_lengths);$tbl.=generate_row(explode("~","Mar 1, 2013~Buncha Junk~J53~606606~48132~34567~106.50~request 104294501, minimum charge per job of $23.00"),$field_orientations,$field_lengths);$tbl.=generate_row(explode("~","Mar 1, 2013~Insane Document~LLX035~48440~30378~222~11.50~request 104294501, minimum charge per job of $23.00"),$field_orientations,$field_lengths);$tbl.=generate_row(explode("~","Mar 1, 2013~My Manifesto~KNJ222~414~8075~73009~50.25~request 104294501, minimum charge per job of $23.00"),$field_orientations,$field_lengths);$tbl.=generate_row(explode("~","Mar 1, 2013~I dont believe it~1105~23101~87601~93340~232.32~request 104294501, minimum charge per job of $23.00"),$field_orientations,$field_lengths);$tbl.=generate_row(explode("~","Mar 1, 2013~What, Me Worry?~KRX455~959~91730~50857~41.41~request 104294501, minimum charge per job of $23.00"),$field_orientations,$field_lengths);$tbl.='</table>';//print($tbl);//exit(0);$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');$pdf->writeHTML($tbl,true,false,false,false,'');// -----------------------------------------------------------------------------//Close and output PDF document$pdf->Output('example_048_honk.pdf','I');//============================================================+// END OF FILE//============================================================+
At this point I haven't changed that much from the original example.
I am just trying to get my format settled before
continuing on with generating real data. I apologize for the weird indentation, due to
rebellious language-sensitive editor. Rather than having you figure out the actual HTML
generated by the PHP functions, here it is:
<tableborder="1"cellpadding="2"cellspacing="2"><thead><trstyle="background-color:#FFFF00;color:#0000FF;"><tdalign="center"width="50">Date</td><tdalign="center"width="200">Job Name</td><tdalign="center"width="40">Client Code</td><tdalign="center"width="40">Client PO Number</td><tdalign="center"width="40">Your PO Number</td><tdalign="center"width="40">Job Number</td><tdalign="center"width="40">Amount</td><tdalign="center"width="200">Remarks</td></tr></thead><tr><tdalign="center"width="50">Mar 1, 2013</td><tdalign="left"width="200">My Terrific Job</td><tdalign="center"width="40">K47</td><tdalign="center"width="40">4405</td><tdalign="center"width="40">20131</td><tdalign="center"width="40">1105</td><tdalign="right"width="40">12.34</td><tdalign="left"width="200">request 104294501, minimum charge per job of
$23.00</td></tr><tr><tdalign="center"width="50">Mar 1, 2013</td><tdalign="left"width="200">Buncha Junk</td><tdalign="center"width="40">J53</td><tdalign="center"width="40">606606</td><tdalign="center"width="40">48132</td><tdalign="center"width="40">34567</td><tdalign="right"width="40">106.50</td><tdalign="left"width="200">request 104294501, minimum charge per job of
$23.00</td></tr><tr><tdalign="center"width="50">Mar 1, 2013</td><tdalign="left"width="200">Insane Document</td><tdalign="center"width="40">LLX035</td><tdalign="center"width="40">48440</td><tdalign="center"width="40">30378</td><tdalign="center"width="40">222</td><tdalign="right"width="40">11.50</td><tdalign="left"width="200">request 104294501, minimum charge per job of
$23.00</td></tr><tr><tdalign="center"width="50">Mar 1, 2013</td><tdalign="left"width="200">My Manifesto</td><tdalign="center"width="40">KNJ222</td><tdalign="center"width="40">414</td><tdalign="center"width="40">8075</td><tdalign="center"width="40">73009</td><tdalign="right"width="40">50.25</td><tdalign="left"width="200">request 104294501, minimum charge per job of
$23.00</td></tr><tr><tdalign="center"width="50">Mar 1, 2013</td><tdalign="left"width="200">I dont believe it</td><tdalign="center"width="40">1105</td><tdalign="center"width="40">23101</td><tdalign="center"width="40">87601</td><tdalign="center"width="40">93340</td><tdalign="right"width="40">232.32</td><tdalign="left"width="200">request 104294501, minimum charge per job of
$23.00</td></tr><tr><tdalign="center"width="50">Mar 1, 2013</td><tdalign="left"width="200">What, Me Worry?</td><tdalign="center"width="40">KRX455</td><tdalign="center"width="40">959</td><tdalign="center"width="40">91730</td><tdalign="center"width="40">50857</td><tdalign="right"width="40">41.41</td><tdalign="left"width="200">request 104294501, minimum charge per job of
$23.00</td></tr></table>
So I'm not sure where it gets the idea that I have output anything.
As a side note, I am getting a lot of these warnings:
Warning: array_push() expects parameter 1 to be array, null given in /Applications/AMPPS/www/tcpdf/tcpdf.php on line 16878
Warning: array_push() expects parameter 1 to be array, null given in /Applications/AMPPS/www/tcpdf/tcpdf.php on line 16878
Warning: array_push() expects parameter 1 to be array, null given in /Applications/AMPPS/www/tcpdf/tcpdf.php on line 16878
Warning: array_push() expects parameter 1 to be array, null given in /Applications/AMPPS/www/tcpdf/tcpdf.php on line 16878
Warning: Invalid argument supplied for foreach() in /Applications/AMPPS/www/tcpdf/tcpdf.php on line 19375
Warning: Invalid argument supplied for foreach() in /Applications/AMPPS/www/tcpdf/tcpdf.php on line 19407
Warning: array_push() expects parameter 1 to be array, null given in /Applications/AMPPS/www/tcpdf/tcpdf.php on line 16878
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Never mind. I found the error. There was an extra that hosed everything. It didn't show up above, because the prettyprinter that formatted the HTML fixed the error without telling me. The original was all one line, so prettyprint.
It would have been nice for it to TELL me something was wrong with my HTML instead of doing weird things, but okay.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In hindsight, it all makes perfect sense. The unbalanced HTML caused all the warning messages about arrays, and those messages were the output that caused the total failure. It was complaining about the output it was generating itself.
If you ever see warnings like that, check your HTML.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks. That is fine if the HTML is coming from some external source, but if I am generating it, as in this case, I should be generating it correctly. The pretty formatting would be unnecessary overhead due to my own sloppiness. But I will keep that in mind for the former case.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not sure where I am writing to the output stream before calling $pdf->Output.
I did have a print statement for the HTML, but that was commented out.
I basically took the example and replaced the canned table with my own.
Here is the redone example:
At this point I haven't changed that much from the original example.
I am just trying to get my format settled before
continuing on with generating real data. I apologize for the weird indentation, due to
rebellious language-sensitive editor. Rather than having you figure out the actual HTML
generated by the PHP functions, here it is:
So I'm not sure where it gets the idea that I have output anything.
As a side note, I am getting a lot of these warnings:
Never mind. I found the error. There was an extra that hosed everything. It didn't show up above, because the prettyprinter that formatted the HTML fixed the error without telling me. The original was all one line, so prettyprint.
It would have been nice for it to TELL me something was wrong with my HTML instead of doing weird things, but okay.
The editor ate the HTML code. There was an extra < / T R >
In hindsight, it all makes perfect sense. The unbalanced HTML caused all the warning messages about arrays, and those messages were the output that caused the total failure. It was complaining about the output it was generating itself.
If you ever see warnings like that, check your HTML.
Before sending HTML string to TCPDF you should send it to some pretty formater e.g. tidy - it would fix up invalid markups for you. Example:
Last edit: Lubos Dz 2014-04-16
Thanks. That is fine if the HTML is coming from some external source, but if I am generating it, as in this case, I should be generating it correctly. The pretty formatting would be unnecessary overhead due to my own sloppiness. But I will keep that in mind for the former case.