Forum


Replies: 5   Views: 3123
Pstyles on addheading getting overriden
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 admin  · 09-02-2017 - 07:22

Hello,

When working with addHeading, some default styles are added is they are not set (bold, keepLines, keepNext, widowControl, sz and font).

You have two approaches to accoomplish what you need: use addText an the headingLevel option or overwrite the default values when callin addHeading.

This is a simple sample of both options

<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

// style options
$style = array(
    'font' => 'Verdana',
    'fontSize' => '28',
);

//Create custom style
$docx->createParagraphStyle('myStyle', $style);

$text = 'Sample heading.';
$docx->addHeading($text, 1, array('pStyle' => 'myStyle', 'fontSize' => '14', 'font' => 'Verdana'));

$text = 'Sample paragraph.';
$docx->addText($text, array('pStyle' => 'myStyle', 'headingLevel' => 1));

$docx->addText('Other paragraph');

$docx->createDocx('output');

 

Regards.