【发布时间】:2021-08-18 13:59:46
【问题描述】:
我目前正在使用 PDFlib 处理我的第一个项目,并且需要创建一个包含多个已定义文本的文本流。但我的问题是,在这些文本之间没有换行符,第二个文本就在第一个文本的最后一个词之后开始。两个词之间甚至没有一个不间断的空格。
这是我的代码中的一个示例:
// First Paragraph
$optlist = "font=" . $fontRegular .
" fontsize=10" .
" fillcolor=black" .
" wordspacing=0";
$tf = $p->add_textflow(0, $firstParaqraph, $optlist);
if ($tf == 0) {
throw new Exception("Error: " . $p->get_errmsg());
}
// Second Paragraph
$optlist = "font=" . $fontRegular .
" fontsize=10" .
" fillcolor=black" .
" wordspacing=0";
$tf = $p->add_textflow($tf, $secondParaqraph, $optlist);
if ($tf == 0) {
throw new Exception("Error: " . $p->get_errmsg());
}
do {
$optlist = "blind=false";
$result = $p->fit_textflow($tf, $x + 10, 0, $textStartHalf+60, $y, "");
} while ($result == "_boxfull");
if ($result == "_stop") {
$infoHeight = $p->info_textflow($tf,'textheight');
$count = $p->info_textflow($tf, 'boxlinecount');
$y = $y - $infoHeight;
$y = $y - ($infoHeight / $count);
}
也许有人可以帮助我,我将不胜感激!
【问题讨论】:
-
在行尾添加“\n”或“\r\n”。这将创建一个回车。像这样: $tf = $p->add_textflow(0, $firstParaqraph."\n\n", $optlist); 或 $tf = $p->add_textflow(0, $firstParaqraph."\r\n\r\n", $optlist);
-
@Patfreeze 非常感谢!这工作得很好! :)