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

时间:2017-06-14 15:13:50

标签: 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');
    ?> 

1 个答案:

答案 0 :(得分:0)

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