gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 18:47:00 29 4
gpt4 key购买 nike

我正在使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com