php - 保留使用 tcpdf 创建的 pdf 中的换行符和行间距

标签 php mysql

我正在使用 tcpdf (php,mysql) 库创建 pdf。我想以 pdf 形式显示数据库中的数据。意味着我想显示换行符和行间距。

示例: 假设数据库中的项目副标题是这样的。

    The Philadelphia Foot Patrol Experiment, a randomized control trial 
    conducted by Temple University, has shown that foot patrols reduce 
    crime.

    [1] With the resources to patrol 60 locations, researchers identified 
    the highest violent crime corners in the city, using data from 2006 to 
    2008. Police commanders designed 120 foot patrol areas around these 
    corners, 

但是输出是这样的

    The Philadelphia Foot Patrol Experiment, a randomized control trial 
    conducted by Temple University, has shown that foot patrols reduce 
    crime.[1] With the resources to patrol 60 locations, researchers 
    identified the highest violent crime corners in the city, using data 
    from 2006 to 2008. Police commanders designed 120 foot patrol areas 
    around these corners, 

这是codeigniter中的查看代码,我编写的是生成pdf

    <?php 
    $tcpdf;
    $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $obj_pdf->SetCreator(PDF_CREATOR);
    $obj_pdf->SetAuthor('Finvensys Technologies Pvt. Ltd.');
    $obj_pdf->SetTitle('Proposal Writing');
    $obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, @$table->projectTitle);
    $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN,'', 14));
    $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '',9));
    $obj_pdf->SetDefaultMonospacedFont('helvetica');
    $obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $obj_pdf->SetFont('helvetica', '', 12);
    $obj_pdf->setFontSubsetting(false);
    $obj_pdf->AddPage();
    ob_start(); ?>

                <table border="1px" align="left" style="width=100%">
                <tr >
                     <td style="width:25%"><b>Project subtitle</b></td>  
                     <td style="width:75%"><?php echo @$table->projectSubTitle; ?></td>
                </tr>
                </table>

    <?php $title=@$table->projectTitle; ?>
    <?php
    $content = ob_get_contents();
    ob_end_clean();
    $obj_pdf->writeHTML($content, true, false, true, false, '');
    $obj_pdf->Output($title.'.pdf', 'I');
    ?> 

最佳答案

这取决于您使用的函数,但很可能您需要使用 <br>而不是\n (标准 LF 字符通常存储在数据库文本字段中)。请参阅861809有关更多详细信息,只需替换 \n (或 \r\n 如果您的文本也有 CR)与 <br>并且 tcpdf 应该正确地为您呈现基本的 HTML 标签。

关于php - 保留使用 tcpdf 创建的 pdf 中的换行符和行间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548605/

相关文章:

php - 解析错误: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

php - 根据另一个表上的相关 csv id 从表中获取行

MySQL:在列列表中使用 GROUP BY 与子选择

mysql - wordpress插件sql语法

mysql - 避免MySQL中同一记录的多次输出

javascript - 如何? PHP 从 &lt;script&gt; 中回显数据

php - litespeed - fatal error : Call to undefined function curl_init()

php - 如何通过AJAX将Jquery可拖动UI与mysql连接

php - 如何返回我在同一查询中创建/或之前创建的记录

MySQL : Different behaviors depending on WHERE result