在.pdf中显示textareas的问题

时间:2012-12-03 12:49:52

标签: php html pdf textarea fpdf

我有一个包含宽度为30列的textarea的表单。此textarea和其他一些文本应通过FPDF显示在.pdf中。 textarea显示如下:

$text=$row->fehlerbeschreibung;
$text=str_replace(array("\r\n", "\n", "\r"),"",$text);
$pdf->MultiCell(0,6,$text);

你知道我想忽略由于30个cols的宽度而发生的换行。 但是,每当您按Enter键创建换行符时,都应显示换行符。 为了避免这个问题,换行符的编码有什么不同吗?或者你知道另一种方式吗?

4 个答案:

答案 0 :(得分:1)

只需使用MultiCell

示例:

$this->MultiCell(60,5,$Variable);

答案 1 :(得分:0)

仅在按Enter键时创建换行符,因此您应该通过

进行拆分
$array = explode("\n",$string);

然后循环遍历数组;

foreach($array  as $key => $item) {
$pdf->MultiCell(0,6,$item);
$pdf->Ln();
}

答案 2 :(得分:0)

请考虑您的textarea字段是历史记录。你可以这样做:

$lengthofhistory = strlen($_SESSION['history']); 
$pdf- >SetFont('Helvetica','',10); $start = 0; $space = 0;
for($i=0;$i<=$lengthofhistory;$i++)
{
$char = substr( $_SESSION['history'], $i, 1 );
if($char == ' ') { $space = $space + 1; 
if($space == 18) { $substring =   substr($_SESSION['history'],$start,$i- $start); 
$pdf->Cell(0,5,$substring,0,1,'L'); $start = $i+1; $space = 0; } }
}
$substring = substr($_SESSION['history'],$start,$lengthofcomplaints-$start);
$pdf->Cell(0,5,$substring,0,1,'L');

答案 3 :(得分:0)

我建议使用功能nl2br()