0

I'm using odt file as a template for my transcripts and I'm using php to insert the transcript in the odt file which then outputs a correctly formated odt file but there is some text that I want to center horizontally for which I've written this code

$transcript .= "<text:p text:style-name=\"CenterText\">Proceedings</text:p>";

from liber office I have added a paragraph style called CenterText and I have set the alignment to center to make it work but for some reason the text proceedings is not even being rendered.

can somebody please tell me what might be wrong and how I can fix the issue

thanks

Tarun
  • 37
  • 7

1 Answers1

1

If you're going to create documents by hand, you're going to have a bad time. Use PHPWord to easily create .odt files. There you can use

$PHPWord->addParagraphStyle('CenterText', array('align'=>'both')

$section->addText($text, 'CenterText');

to center your text.

5px
  • 131
  • 9
  • I Can't use PHPWord since it will require php version 7 and I'm on version 5 also I can't update my php version since it will break a lot of things so is there any other way to do it – Tarun Aug 18 '23 at 10:39
  • @Tarun Do you have PHP 5.3.3 or higher? You can use an [older version](https://github.com/PHPOffice/PHPWord/releases/tag/0.18.3) that's compatible. For Composer, use `composer require phpoffice/phpword:0.18.3` – 5px Aug 18 '23 at 10:46
  • `Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 5.6.40-65+ubuntu18.04.1+deb.sury.org+1, please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.` this is the error I get after running the command that you gave me (I'm using version 5.6.40) – Tarun Aug 18 '23 at 11:11
  • Like they said, try Composer 2.2. `composer self-update --2.2` – 5px Aug 18 '23 at 11:18
  • I already tried it but it gives me the same error – Tarun Aug 18 '23 at 11:25
  • You should update your PHP then. You probably don't want to hear it, but if you don't it's gonna bite you in the a** someday. 5.3.3 is ancient, it's 13 years old already. – 5px Aug 18 '23 at 11:28
  • Thanks for the help Chix I'll talk with my team and see if they are ok with updating the php version – Tarun Aug 18 '23 at 11:41
  • @Tarun At the very least, you should move to [7.0](https://www.php.net/manual/en/migration70.php). It's a good tradeoff between compatibility with newer plugins and your existing codebase. More info here: https://stackoverflow.com/questions/71732360/upgrade-php-version-in-project-from-5-6-to-8-1 – 5px Aug 18 '23 at 11:48