我需要将一些HTML代码转换为PDF,并尝试使用TCPDF总是向我发送此PHP错误:
Undefined offset: 1
Cannot modify header information - headers already sent
TCPDF ERROR: Some data has already been output to browser, can't send PDF file
我一点一点地放在这段代码中:
$tbl = <<<EOD
<table align='center' class='tablatitular'>
<tr><td colspan='2' class='nombreseccion'>One</td></tr>
<tr><td colspan='2' class='filatitulo'><b>Two</b></td></tr>
<tr><td class='cuadrocontenido' align='left' rowspan='2'>Other thing</td></tr>
<tr><td>Column1</td><td><b>Column2</b></td></tr>
EOD;
如果我最后一次
<tr><td>Column1</td><td><b>Column2</b></td></tr>
这是有效的,但是如果我再次把这一行放回去,两个人就把错误发给我了......
为什么呢?它的HTML代码没有?这不支持两个?
这是我的所有文件:
require_once('tcpdf/tcpdf.php');
// Creacion documento [variables en tcpdf / config]
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle("Resumen");
$pdf->SetSubject('Datos Resumen');
//$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// Cabecera [permite insertar logo y todo...]
//$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, 'Example of HTML tables', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('helvetica', '', 8);
// -----------------------------------------------------------------------------
$tbl = <<<EOD
<table align='center' class='tablatitular'>
<tr><td colspan='2' class='nombreseccion'>One</td></tr>
<tr><td colspan='2' class='filatitulo'><b>Two</b></td></tr>
<tr><td class='cuadrocontenido' align='left' rowspan='2'>Other thing</td></tr>
<tr><td>Column1</td><td><b>Column2</b></td></tr>
</table>
EOD;
$pdf->writeHTML($tbl, true, false, false, false, '');
// -----------------------------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_048.pdf', 'I');