1

I am using PphPresentation library to create powepoint presentations.

I am trying to create a newline inside of textshape.

This is part of the code

$currentSlide=$objPHPPresentation->createSlide();

$textRun = $shape->createTextRun('Estado de Fuerza: '.$personal['ef'].' Elementos. '.'Población: '.$personal['pb'].' hab. '.'Faltante: '.$personal['fal'].' Elementos.');

And I get something like this:

Fuerza: 0 Elementos Población: 10987 hab. Faltante: -31 Elementos.

But what I want to get is this:

Fuerza: 0 Elementos

Población: 10987 hab.

Faltante: -31 Elementos.
Maurocrispin
  • 242
  • 2
  • 14

3 Answers3

3

Another option of getting new line while having same font properties for all the lines is to use paragraph:

$textParagraph = $shape->createParagraph();
$textParagraph->getFont()->setSize(14)->setColor($colorBlack);

$shape->getActiveParagraph()->createTextRun("Estado de Fuerza: ".$personal["ef"]." Elementos.");
$shape->getActiveParagraph()->createBreak();
$shape->getActiveParagraph()->createTextRun("Población: ".$personal["pb"]." hab. ");
$shape->getActiveParagraph()->createBreak();
$shape->getActiveParagraph()->createTextRun("Faltante: ".$personal["fal"]." Elementos.");
Ali Sayani
  • 33
  • 7
0

I am having the same issue. I just found this in the samples. I believe you need to add each line separately. I have to re-write how I build my array, then I'll test it but here is the sample code:

    $shape->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);



    $shape->createTextRun('A class library');
    $shape->createParagraph()->createTextRun('Written in PHP');
    $shape->createParagraph()->createTextRun('Representing a presentation');
    $shape->createParagraph()->createTextRun('Supports writing to different file formats');
user2332467
  • 119
  • 1
  • 11
0

I have realized that this library has a method for it.

I simply did it this way.

$textRun = $shape->createTextRun("Estado de Fuerza: ".$personal["ef"]." Elementos.");
$textRun->getFont()->setSize(14)->setColor($colorBlack);

$shape->createBreak();

$textRun = $shape->createTextRun("Población: ".$personal["pb"]." hab. ");

$shape->createBreak();

$textRun = $shape->createTextRun("Faltante: ".$personal["fal"]." Elementos.");

And I got:

Fuerza: 0 Elementos

Población: 10987 hab.

Faltante: -31 Elementos.

Three different lines in the same Powerpoint Text Box.

Maurocrispin
  • 242
  • 2
  • 14