Reputation: 71
When I use addText()
it works fine with align=center
, left or right, but when I try use align=justify
script works without problems, but when I try to open .docx
file it gives me error and file is not openning.
It would be appreciated if someone knows solution.
$text = "some text";
$PHPWord->addFontStyle('r2Style', array('bold'=>false, 'italic'=>false, 'size'=>12));
$PHPWord->addParagraphStyle('p2Style', array('align'=>'center', 'spaceAfter'=>100));
$section->addText($text, 'r2Style', 'p2Style');
Upvotes: 7
Views: 25682
Reputation: 181
try change 'align'=>'left'
to 'align'=>'both'
$text = "some text";
$PHPWord->addFontStyle('r2Style', array('bold'=>false, 'italic'=>false, 'size'=>12));
$PHPWord->addParagraphStyle('p2Style', array('align'=>'both', 'spaceAfter'=>100));
$section->addText($text, 'r2Style', 'p2Style');
Upvotes: 11
Reputation: 51
in src\PhpWord\SimpleType\Jc.php you will find the list of valid alignment options. "justify" is not (and has not been as far as I can tell) a valid option.
const START = 'start';
const CENTER = 'center';
const END = 'end';
const BOTH = 'both';
const MEDIUM_KASHIDA = 'mediumKashida';
const DISTRIBUTE = 'distribute';
const NUM_TAB = 'numTab';
const HIGH_KASHIDA = 'highKashida';
const LOW_KASHIDA = 'lowKashida';
const THAI_DISTRIBUTE = 'thaiDistribute';
"distribute" is close, but the last line will be spread across the width of the paragraph even if it is a single word. I have had success with "thaiDistribute" and "lowKashida" as values for the "align" property. Both give a decent "Justify" as you would expect in Word.
Upvotes: 5