Home > Enterprise >  How do I create a LineBreak every 60 characters ? FPDF / PHP
How do I create a LineBreak every 60 characters ? FPDF / PHP

Time:01-17

I would like to use this configuration and make a line break every 60 characters.

The example i saw on the other pages does not explain how i can make a line break every 60 characters.

$pdf->Text(77, 94, utf8_decode("$objet"));

CodePudding user response:

You can use wordwrap to break sentences into multiple lines without breaking the word and without the line exceeding the desired length.

Then simply iterate the lines, increasing the Y coordinate on each iteration, adjust the Y coordinate as necessary to suit the size of your text.

$object = "This is a very long text that I want to break into multiple lines every 60 characters.";
$object_lines = wordwrap($object, 60, "\n", true);
$object_lines = explode("\n", $object_lines);
$y = 94;

foreach ($object_lines as $line) {
    $pdf->Text(77, $y, utf8_decode($line));
    $y  = 10;
}
  • Related