FPDF附加“Write-Html-Tables”,在单元格中具有多单元支持/换行符

I use the FPDF add-on "write-html-tables". The add-on works really good with HTML tables.

http://fpdf.de/downloads/add-ons/write-html-tables.html

But I have a problem with line breaks. If the content of a cell is too long, I can't make a line break inside the cell and the text overlaps the next cell.

I tried to extend the code from the "write-html-tables" add-on but it doesn't work. Does anyone have a tip for me how can I expand the add-on?

It is possible that FPDF Add-on Write-Html-Tables has mistakes with new lines in a table cell. I checked it with and <br> – the same mistake.

Recommended solution

If you are using HTML code to build tables for PDF documents generated with the FPDF library, then I would like to recommend the FPDF easyTable project (FPDF Add-on).

You have to download easyTable.php, formatedstring.php, exfpdf.php from this project and to save this files in the FPDF folder. Do not forget to delete all symbols after ?> on the end of your PHP files.

Example:

<?php
include 'fpdf.php';
include 'exfpdf.php';
include 'easyTable.php';

$pdf = new exFPDF();
$pdf->AddPage(); 
$pdf->SetFont('helvetica','',10);

$table = new easyTable($pdf, '%{70,30}', 'border:1');

$table->easyCell('If the content of a cell is too long, I can make a line break inside the cell and the text does not overlap the next cell.', 'colspan:2; bgcolor:#b3ccff');
$table->printRow();

$table->easyCell('If the content of a cell is too long, I can make a line break inside the cell and the text does not overlap the next cell.');
$table->easyCell('Some values 1');
$table->printRow();

//the next line is double quoted because new line(
) should be interpreted
$table->easyCell("If the content of a cell is too long, I can make a line break inside the cell and

the text does not overlap the next cell.");
$table->easyCell('Some values 2');
$table->printRow();

$table->endTable(5);

$pdf->Output();
?>

Output example as part of screenshot:

fpdf easytable example

If you want break lines manually, then you should use double quotes " around your instead of single quotes '.

From the docs:

The simplest way to specify a string is to enclose it in single quotes (the character ').

To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash, double it (\\). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as or , will be output literally as specified rather than having any special meaning.

If the string is enclosed in double-quotes ("), PHP will interpret [escape sequences such as ].