Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting global paragraph style with phpword

Tags:

php

phpword

I'm using PHPWord and would like to set the spaceAfter paragraph style to 0 for every paragraph. Unfortunately, I'm unaware of how to do this globally. You can set the font size / name globally by doing this:

$phpWord->setDefaultFontName('Times New Roman');
$phpWord->setDefaultFontSize(12);

But how might I set the spaceAfter default paragraph style?

Per http://phpword.readthedocs.org/en/latest/elements.html#paragraph-style I can also set it every time I call addText() (by setting the third parameter) but that could get old, fast.

Setting it globally would be the ideal approach.

I'm using Beta 0.6.3.

Any ideas?

like image 666
neubert Avatar asked Aug 20 '15 20:08

neubert


1 Answers

The Beta 0.6.3 version (in CodePlex) is an old inactive project - there is a new active version (that is based on that CodePlex project) in GitHub that you can find here PhpWord: GitHub

And with the new project version (no idea if this applicable in the old 0.6.3 as well), you can set the default paragraph style like this (copied from Sample_08_ParagraphPagination.php):

$phpWord->setDefaultParagraphStyle(
    array(
        'align'      => 'both',
        'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12),
        'spacing'    => 120,
        )
    );
like image 185
ejuhjav Avatar answered Sep 27 '22 21:09

ejuhjav