我有一个很长的文本,我想添加到FPDF格式,我正在使用MultiCell()来实现这一点,它工作得很好。我面临的唯一问题是文本几乎到了页面右侧的末尾。我不希望这种情况发生,相反,我希望多个单元格添加一个换行符,并继续到下一行。如何手动指定MultiCell添加换行符?我可以提供x轴的限制或每行字符的限制吗?
<?php
header('Content-Type: text/html; charset=utf-8');
require_once __DIR__ . '/vendor/autoload.php';
require_once('FPDI/autoload.php');
require_once('fpdf/fpdf.php');
require_once('FPDI/Fpdi.php');
$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile('Literature.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 0, 0, 297, 420, true);
$pdf->SetTextColor(0, 0, 40);
$Text = "As they rounded a bend in the path that ran beside the river, Lara recognized the silhouette of a fig tree atop a nearby hill. The weather was hot and the days were long. The fig tree was in full leaf, but not yet bearing fruit. Soon Lara spotted other landmarks—an outcropping of limestone beside the path that had a silhouette like a man’s face, a marshy spot beside the river where the waterfowl were easily startled, a tall tree that looked like a man with his arms upraised. They were drawing near to the place where there was an island in the river. The island was a good spot to make camp. They would sleep on the island tonight."
$pdf->SetXY(10, 50);
$pdf->Multicell(0, 8, $Text, 0, 'L', false); //Facing problem here
...
...
?>发布于 2021-09-14 17:35:09
MultiCell的第一个参数是0,手册中提到:
单元格的
宽度。如果为0,则它们向上延伸到页面的右边距。
因此,将该零更改为您想要宽度。
https://stackoverflow.com/questions/69175639
复制相似问题