Forum


Replies: 1   Views: 2532
Using pstyle for addheading() only applies part of the styles
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by wadmiraal  · 16-02-2018 - 11:18

Hi, if I use the following:

// Default styles.
$style = array(
  'fontSize' => 18,
  'font' => 'Verdana',
  'lineSpacing' => 240,
  'spacingTop' => 0,
  'spacingBottom' => 0,
);

$docx->createParagraphStyle('h1', array(
  'bold' => TRUE,
  'color' => '006283',
  'caps' => TRUE,
  'pageBreakBefore' => TRUE,
) + $style);

$docx->addHeading("My heading", 1, array('pStyle' => "h1"));

It doesn't apply the font size, nor the font family. The other styles are applied. 

Why? If I pass the fontSize and font parameters to the options array directly, it works (although I would have to divide the font size by 2). Why?

Posted by admin  · 16-02-2018 - 11:54

Hello,

The addHeading method adds some default styles that can't be overwriten using a paragraph style (these default styles are set as Word inline styles):

if (!isset($options['b'])) {
  $options['b'] = 'on';
}
if (!isset($options['keepLines'])) {
  $options['keepLines'] = 'on';
}
if (!isset($options['keepNext'])) {
  $options['keepNext'] = 'on';
}
if (!isset($options['widowControl'])) {
  $options['widowControl'] = 'on';
}
if (!isset($options['sz'])) {
  $options['sz'] = max(15 - $level, 10);
}
if (!isset($options['font'])) {
  $options['font'] = 'Cambria';
}

You need to set that values using the options of the addHeading method, or use the addText method with the headingLevel option that doesn't add default inline styles.

Regards.