【问题标题】:PDFlib PHP linebreak in textflow文本流中的 PDFlib PHP 换行符
【发布时间】: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 非常感谢!这工作得很好! :)

标签: php pdf pdflib


【解决方案1】:

现在不确定我的评论是否正常,但添加:

$tf = $p->add_textflow(0, $firstParaqraph."\n\n", $optlist);

// or

$tf = $p->add_textflow(0, $firstParaqraph."\r\n\r\n", $optlist);

您需要的示例:https://www.pdflib.com/pdflib-cookbook/textflow/distance_between_paragraphs/php/

【讨论】:

  • 再次感谢,这很好用! Tbh 我什至忽略了食谱中的这个例子。我只是在文档中搜索“换行符”,并查看了食谱中的另外两个示例,但不是这个……但是您的回答真的很有帮助!
猜你喜欢
  • 1970-01-01
  • 2015-11-26
  • 2012-03-16
  • 1970-01-01
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 2011-01-04
  • 2011-06-19
相关资源
最近更新 更多