Search code examples
phppdfpdflib

PDFlib PHP linebreak in textflow


I'm currently working on my first project with PDFlib and need to create a textflow which consists of multiple defined texts. But my problem is, that between those Texts there is no line breaking, the second text just starts right after the last word of the first one. There's not even a non-breaking space between the two words.

Here's an example out of my code:

// 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);
    }

Maybe someone can help me with it, I would really appreciate it!


Solution

  • Not sure now if my comment is ok or not but adding :

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

    Example of what you need : https://www.pdflib.com/pdflib-cookbook/textflow/distance_between_paragraphs/php/