dongyi2534 2018-07-24 16:49
浏览 108

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?

  • 写回答

1条回答 默认 最新

  • dongsuichi6529 2018-07-27 14:51
    关注

    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 ].

    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)