Forum


Replies: 5   Views: 3127
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 ironinthesoul  · 30-01-2017 - 09:27

I have created a sytle called Level 1 Heading with font and font size characteristics (Verdana, 14pt) and I apply it successfully to a heading in a Word document.

 

However, in the document the font and style are not correct and the style name i displayed as Level 1 Heading + (Latin) Cambria 12pt. And, the text does look to be in Cambria 12pt! 

If I then clear formatting in the Word document and reapply LEvel 1 Heading from the list it looks the way I want it to. So, the problem is not with the style itself.

Nowwhere in my syle creation, or in the ading of the text is Cambria or 12pt mentioned at all.

How is this rogue formatting finding its way in to my documents?

 

Posted by admin  · 30-01-2017 - 09:37

Hello,

As your username doesn't have any license tied, please post which license and version of phpdocx are you using.

Regards.

Posted by ironinthesoul  · 08-02-2017 - 19:23

Hi,

 

Sorry, I'm just the developer, not the licencee. We are using the Corporate 5.5 version.

If you need more sensitive information please email me.

Kind regards,

Michael

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.

Posted by ironinthesoul  · 13-02-2017 - 10:43

Thanks very much.

Adding overrides to the style seems a little redundant. I have created a paragraph style which adds the font and size so it seems wrong to have to add it again. Is this a glitch?

However, adding the style I want and a headingLevel to addText has solved the problem.

Thanks for your help,

 

Michael

Posted by admin  · 13-02-2017 - 11:06

Hello,

The addHeading method adds some rPr default styles that overwrite pStyle (only for headings):

        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';
        }

The addHeading method is a shortcut to the addText method that adds a headingLevel. We recommend you to read the code in CreateDocx.inc to understand the method and its default options.

Regards.